[Gnucash-changes] Fix double-free error in generic importer.

Christian Stimming cstim at cvs.gnucash.org
Sun Oct 16 05:38:21 EDT 2005


Log Message:
-----------
Fix double-free error in generic importer.

2005-10-16  Christian Stimming  <stimming at tuhh.de>

	* src/import-export/import-backend.c: Woohoo! Tracked down and
	fixed a nasty double-free error when the importer reconciled
	existing transactions.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/import-export:
        import-backend.c
        import-main-matcher.h

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.340
retrieving revision 1.1487.2.341
diff -LChangeLog -LChangeLog -u -r1.1487.2.340 -r1.1487.2.341
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,9 @@
+2005-10-16  Christian Stimming  <stimming at tuhh.de>
+
+	* src/import-export/import-backend.c: Woohoo! Tracked down and
+	fixed a nasty double-free error when the importer reconciled
+	existing transactions.
+
 2005-10-14  David Hampton  <hampton at employees.org>
 
 	* src/register/register-gnome/gnucash-item-edit.c: Didier Vidal's
Index: import-backend.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/import-backend.c,v
retrieving revision 1.19.2.10
retrieving revision 1.19.2.11
diff -Lsrc/import-export/import-backend.c -Lsrc/import-export/import-backend.c -u -r1.19.2.10 -r1.19.2.11
--- src/import-export/import-backend.c
+++ src/import-export/import-backend.c
@@ -106,7 +106,7 @@
 {
   Transaction * trans;
   Split * split;
-  //GNC_match_probability probability;
+  /*GNC_match_probability probability;*/
   gint probability;
 };
 
@@ -242,8 +242,8 @@
 {
   if (info) {
     g_list_free (info->match_list);
-    /*If the transaction is still open, it must be destroyed*/
-    if(xaccTransIsOpen(info->trans)==TRUE)
+    /*If the transaction exists and is still open, it must be destroyed*/
+    if(info->trans && xaccTransIsOpen(info->trans))
       {
         xaccTransDestroy(info->trans);
         xaccTransCommitEdit(info->trans);
@@ -936,6 +936,8 @@
 	      xaccTransDestroy(trans_info->trans);
 	      /*DEBUG("CommitEdit trans")*/
 	      xaccTransCommitEdit(trans_info->trans);
+	      /* Very important: Make sure the freed transaction is not freed again! */
+	      trans_info->trans = NULL;
 	    }
 	  break;
 	case GNCImport_EDIT:
@@ -983,7 +985,7 @@
     }
   else
     {
-      //printf("test_trans_online_id(): Duplicate found\n");
+      /*printf("test_trans_online_id(): Duplicate found\n");*/
       return 1;
     }
 }
Index: import-main-matcher.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/import-main-matcher.h,v
retrieving revision 1.3.4.1
retrieving revision 1.3.4.2
diff -Lsrc/import-export/import-main-matcher.h -Lsrc/import-export/import-main-matcher.h -u -r1.3.4.1 -r1.3.4.2
--- src/import-export/import-main-matcher.h
+++ src/import-export/import-main-matcher.h
@@ -60,14 +60,15 @@
 /** Deletes the given object. */
 void gnc_gen_trans_list_delete (GNCImportMainMatcher *info);
 
-/** Add a newly imported Transaction to the Transaction Importer.
+/** Add a newly imported Transaction to the Transaction Importer. The Importer takes over ownership of the passed transaction.
  *
  * @param gui The Transaction Importer to use.
  *
  * @param trans The Transaction to add.  The must contain at least one
  * split, and this split must have been associated with an account
  * Only the first split will be used for matching.  The transaction
- * must NOT be commited.
+ * must NOT be commited. The Importer takes over ownership of the
+ * passed transaction.
  */
 void gnc_gen_trans_list_add_trans(GNCImportMainMatcher *gui, Transaction *trans);
 


More information about the gnucash-changes mailing list