GnuCash Daily Diff
Dave Peticolas
peticolas@linas.org
Sat, 19 May 2001 08:03:03 -0500 (CDT)
Index: gnucash/ChangeLog
diff -u gnucash/ChangeLog:1.490 gnucash/ChangeLog:1.492
--- gnucash/ChangeLog:1.490 Fri May 18 05:01:11 2001
+++ gnucash/ChangeLog Sat May 19 05:02:29 2001
@@ -1,4 +1,31 @@
+2001-05-19 Dave Peticolas <dave@krondo.com>
+
+ * src/engine/sixtp.c (gnc_is_our_xml_file): fix mem leak
+
+ * src/engine/io-gncxml-v2.c (gnc_book_load_from_xml_file_v2): fix
+ mem leak
+
+ * src/gnome/window-acct-tree.c: fix mem leak
+
+ * src/doc/design/engine.texinfo: update docs
+
+ * src/gnome/window-acct-tree.c: fix mem leaks
+
+ * src/engine/io-gncxml-v2.c (gnc_counter_end_handler): fix mem
+ leak
+
+ * src/engine/gnc-account-xml-v2.c (account_parent_handler): fix
+ mem leak
+
+ * src/engine/Group.c (xaccFreeAccountGroup): set parent's child
+ pointer to NULL
+ (xaccAccountRemoveGroup): set parent's child pointer to NULL
+
+ * src/engine/sixtp-dom-parsers.c (dom_tree_to_integer): fix mem leak
+
2001-05-18 Dave Peticolas <dave@krondo.com>
+
+ * src/engine/io-gncxml-w.c: remove
* src/engine/Group.h: fix prototype
Index: gnucash/README
diff -u gnucash/README:1.161 gnucash/README:1.162
--- gnucash/README:1.161 Tue May 1 15:57:58 2001
+++ gnucash/README Sat May 19 01:50:33 2001
@@ -479,4 +479,5 @@
patches suitable for submitting to the gnucash development team.
-Thank you.
+Thank you.
+
Index: gnucash/src/doc/design/engine.texinfo
diff -u gnucash/src/doc/design/engine.texinfo:1.38 gnucash/src/doc/design/engine.texinfo:1.39
--- gnucash/src/doc/design/engine.texinfo:1.38 Fri May 18 04:59:58 2001
+++ gnucash/src/doc/design/engine.texinfo Sat May 19 05:02:31 2001
@@ -2095,6 +2095,27 @@
Account Groups do not have key-value frames or GUIDs.
+@menu
+* General Account Group API::
+@end menu
+
+@node General Account Group API, , Account Groups, Account Groups
+@subsection General Account Group API
+
+@deftypefun {AccountGroup *} xaccMallocAccountGroup (void)
+Return a newly-allocated & initialized Account Group.
+The Group must be freed with @code{xaccFreeAccountGroup}.
+@end deftypefun
+
+@deftypefun void xaccFreeAccountGroup (AccountGroup * @var{account_group})
+Free the given Group and all its resources, including the Accounts.
+@end deftypefun
+
+@deftypefun void xaccAccountGroupCommitEdit (AccountGroup * @var{grp})
+Recursively call @code{xaccAccountCommitEdit} on all child accounts
+and their children.
+@end deftypefun
+
@node GNCBooks, Scrub, Account Groups, Engine
@section GNCBooks
Index: gnucash/src/engine/Group.c
diff -u gnucash/src/engine/Group.c:1.80 gnucash/src/engine/Group.c:1.81
--- gnucash/src/engine/Group.c:1.80 Thu May 10 11:12:28 2001
+++ gnucash/src/engine/Group.c Sat May 19 05:02:33 2001
@@ -209,6 +209,8 @@
if (!root_grp) return;
}
+ if (grp->parent) grp->parent->children = NULL;
+
grp->parent = NULL;
grp->balance = gnc_numeric_zero();
g_free (grp);
@@ -536,7 +538,8 @@
if (!acc) return;
grp = acc->children;
-
+
+ if (grp) grp->parent = NULL;
acc->children = NULL;
/* make sure that the parent of the group is marked
Index: gnucash/src/engine/gnc-account-xml-v2.c
diff -u gnucash/src/engine/gnc-account-xml-v2.c:1.18 gnucash/src/engine/gnc-account-xml-v2.c:1.19
--- gnucash/src/engine/gnc-account-xml-v2.c:1.18 Tue May 15 10:52:22 2001
+++ gnucash/src/engine/gnc-account-xml-v2.c Sat May 19 05:02:34 2001
@@ -225,17 +225,22 @@
account_parent_handler (xmlNodePtr node, gpointer act)
{
Account *parent;
- GUID *gid = dom_tree_to_guid(node);
+ GUID *gid;
+ gid = dom_tree_to_guid(node);
g_return_val_if_fail(gid, FALSE);
-
+
parent = xaccAccountLookup(gid);
+ if (!parent)
+ {
+ g_free (gid);
+ g_return_val_if_fail(parent, FALSE);
+ }
- g_return_val_if_fail(parent, FALSE);
-
xaccAccountInsertSubAccount(parent, (Account*)act);
+
+ g_free (gid);
- /* xaccGUIDFree(gid); */
return TRUE;
}
Index: gnucash/src/engine/io-gncxml-v2.c
diff -u gnucash/src/engine/io-gncxml-v2.c:1.13 gnucash/src/engine/io-gncxml-v2.c:1.14
--- gnucash/src/engine/io-gncxml-v2.c:1.13 Sun May 13 05:18:32 2001
+++ gnucash/src/engine/io-gncxml-v2.c Sat May 19 05:02:35 2001
@@ -170,9 +170,12 @@
{
g_warning("string_to_integer failed with input: %s",
strval ? strval : "(null)");
+ g_free (strval);
+ xmlFree (type);
return FALSE;
}
-
+ g_free (strval);
+
if(safe_strcmp(type, "transaction") == 0)
{
sixdata->counter.transactions_total = val;
@@ -189,9 +192,13 @@
{
g_warning("Unknown type: %s",
type ? type : "(null)");
+ xmlFree (type);
return FALSE;
}
+ xmlFree (type);
+ xmlFreeNode(tree);
+
return TRUE;
}
@@ -329,6 +336,9 @@
/* set up various state that is not normally stored in the byte stream */
xaccRecomputeGroupBalance (gnc_book_get_group(book));
+
+ /* destroy the parser */
+ sixtp_destroy (top_parser);
/* start logging again */
xaccLogEnable ();
Index: gnucash/src/engine/io-gncxml-w.c
diff -u gnucash/src/engine/io-gncxml-w.c:1.30 gnucash/src/engine/io-gncxml-w.c:removed
--- gnucash/src/engine/io-gncxml-w.c:1.30 Sun Mar 4 05:09:22 2001
+++ gnucash/src/engine/io-gncxml-w.c Sat May 19 08:02:37 2001
@@ -1,280 +0,0 @@
-/********************************************************************\
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
- * Boston, MA 02111-1307, USA gnu@gnu.org *
-\********************************************************************/
-
-/*
- * io-gncxml-w.c -- write XML-format gnucash data file
- *
- * FUNCTION:
- * Contains routines to write out values for some basic field types
- * Contains routines which specifically write out the account, txn,
- * and split structures, for saving to file.
- * Contains routines for writing out a query, for network transmission.
- *
- * TBD:
- * Much of the contents of this file is 'mundane', and simply
- * dumps C structure contents into xml. This could probably be
- * automated with a bit of meta-description of the C structs ...
- * e.g. even some simple #define macros might help here ...
- *
- * HISTORY:
- * Initial code by Rob Browning 4Q 2000
- * Tuneups by James LewisMoss Dec 2000-Feb 2001
- * Generic I/O hack by Linas Vepstas January 2001
- *
- * Copyright (c) 2000,2001 Gnumatic Incorporated
- */
-
-#include <config.h>
-
-#define _GNU_SOURCE
-
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-xml-helper.h"
-#include "Account.h"
-#include "date.h"
-#include "DateUtils.h"
-#include "Group.h"
-#include "messages.h"
-#include "Query.h"
-#include "Transaction.h"
-#include "TransLog.h"
-#include "gnc-engine.h"
-#include "gnc-engine-util.h"
-
-#include "sixtp-writers.h"
-#include "io-gncxml.h"
-
-#include "AccountP.h" /* just for kvp_data */
-#include "TransactionP.h" /* just for kvp_data */
-
-
-#ifdef USE_GUILE_FOR_DOUBLE_CONVERSION
-#include <guile/gh.h>
-#endif /* USE_GUILE_FOR_DOUBLE_CONVERSION */
-
-static short module = MOD_IO;
-
-/* Pulled from the libxml-1.8.8 header */
-
-static const gchar *gncxml_emacs_trailer =
-"<!-- Local variables: -->\n"
-"<!-- mode: xml -->\n"
-"<!-- End: -->\n";
-
-/* ============================================================== */
-
-static gboolean
-gncxml_append_emacs_trailer(const gchar *filename)
-{
- FILE *toappend;
-
- toappend = fopen(filename, "a+");
- if(!toappend)
- {
- PERR("Unable to append emacs trailer: %s\n", strerror(errno));
- return 0;
- }
-
- fprintf(toappend, gncxml_emacs_trailer);
-
- return fclose(toappend);
-}
-
-#if 0
-/* =============================================================== */
-/* create a new xml document and poke all the query terms into it. */
-
-static xmlDocPtr
-gncxml_new_query_doc (Query *q)
-{
- xmlDocPtr doc;
- xmlNodePtr query_server;
- xmlNodePtr tmpnode;
-
- doc = xmlNewDoc("1.0");
- doc->xmlRootNode = xmlNewDocNode(doc, NULL, "gnc", NULL);
-
- tmpnode = xmlNewTextChild(doc->xmlRootNode, NULL, "version", "1");
- if(!tmpnode) {
- PERR ("can't create new text child");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- query_server = xmlNewTextChild(doc->xmlRootNode, NULL, "query-server", NULL);
- if(!query_server) {
- PERR ("couldn't creat query terms");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- if(!xml_add_query_restorers(query_server, q)) {
- PERR ("couldn't write query server");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- return doc;
-}
-
-#endif
-
-/* =============================================================== */
-/* create a new xml document and poke all account & txn data into it. */
-
-static xmlDocPtr
-gncxml_newdoc (GNCBook *book, int do_txns)
-{
- xmlDocPtr doc;
- xmlNodePtr ledger_data;
- xmlNodePtr tmpnode;
- AccountGroup *group = gnc_book_get_group(book);
- GNCPriceDB *pricedb = gnc_book_get_pricedb(book);
-
- doc = xmlNewDoc("1.0");
- doc->xmlRootNode = xmlNewDocNode(doc, NULL, "gnc", NULL);
-
- tmpnode = xmlNewTextChild(doc->xmlRootNode, NULL, "version", "1");
- if(!tmpnode) {
- PERR ("can't create new text child");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- ledger_data = xmlNewTextChild(doc->xmlRootNode, NULL, "ledger-data", NULL);
- if(!ledger_data) {
- PERR ("couldn't create xml text child");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- if(!xml_add_commodity_restorers(ledger_data)) {
- PERR ("couldn't create commodity restorers");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- if(!xml_add_gnc_pricedb(ledger_data, "pricedb", pricedb)) {
- PERR ("couldn't create pricedb");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- if(!xml_add_account_restorers(ledger_data, group)) {
- PERR ("couldn't account restore");
- xmlFreeDoc(doc);
- return 0x0;
- }
-
- if (do_txns) {
- if(!xml_add_txn_and_split_restorers(ledger_data, group)) {
- PERR ("couldn't txn restore");
- xmlFreeDoc(doc);
- return 0x0;
- }
- }
-
- return doc;
-}
-
-#if 0
-
-/* =============================================================== */
-
-void
-gncxml_write_to_buf (AccountGroup *group, char **bufp, int *sz)
-{
- xmlDocPtr doc;
-
- doc = gncxml_newdoc (group, 1);
- if (!doc) return;
-
- xmlDocDumpMemory (doc, (xmlChar **)bufp, sz);
-
- PINFO ("wrote %d bytes", *sz);
-}
-
-/* =============================================================== */
-
-void
-gncxml_write_group_to_buf (AccountGroup *group, char **bufp, int *sz)
-{
- xmlDocPtr doc;
-
- doc = gncxml_newdoc (group, 0);
- if (!doc) return;
-
- xmlDocDumpMemory (doc, (xmlChar **)bufp, sz);
-
- PINFO ("wrote %d bytes", *sz);
-}
-
-/* =============================================================== */
-
-void
-gncxml_write_query_to_buf (Query *q, char **bufp, int *sz)
-{
- xmlDocPtr doc;
-
- doc = gncxml_new_query_doc (q);
- if (!doc) return;
-
- xmlDocDumpMemory (doc, (xmlChar **)bufp, sz);
-
- PINFO ("wrote %d bytes", *sz);
-}
-
-#endif
-
-/* =============================================================== */
-/* write the account group to a filename */
-
-gboolean
-gnc_book_write_to_xml_file(GNCBook *book, const gchar *filename)
-{
- xmlDocPtr doc;
- int status;
-
- if(!filename) return FALSE;
-
- doc = gncxml_newdoc (book, 1);
- if (!doc) return FALSE;
-
- xmlIndentTreeOutput = TRUE;
-
- status = xmlSaveFile(filename, doc);
- xmlFreeDoc(doc);
-
- gncxml_append_emacs_trailer(filename);
-
- /* FIXME: This gives me a non-zero result, even when everything's fine ???
- status = xmlDocDump(outfile, doc);
-
- This crashes with the current libxml, but they don't document that
- they close the file, so I don't know why...
- assert(fclose(outfile) == 0);
- */
- return(status != -1);
-}
-
-/* ========================= END OF FILE ============================ */
Index: gnucash/src/engine/sixtp-dom-parsers.c
diff -u gnucash/src/engine/sixtp-dom-parsers.c:1.17 gnucash/src/engine/sixtp-dom-parsers.c:1.18
--- gnucash/src/engine/sixtp-dom-parsers.c:1.17 Tue Apr 17 04:32:04 2001
+++ gnucash/src/engine/sixtp-dom-parsers.c Sat May 19 05:02:35 2001
@@ -95,17 +95,15 @@
dom_tree_to_integer(xmlNodePtr node, gint64 *daint)
{
gchar *text;
-
+ gboolean ret;
+
text = dom_tree_to_text(node);
- if(string_to_gint64(text, daint))
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+ ret = string_to_gint64(text, daint);
+
+ g_free (text);
+
+ return ret;
}
kvp_value*
@@ -306,12 +304,18 @@
kvp_value*
dom_tree_to_kvp_value(xmlNodePtr node)
{
+ xmlChar *xml_type;
gchar *type;
struct kvp_val_converter *mark;
kvp_value *ret = NULL;
-
- type = xmlGetProp(node, "type");
- if(!type)
+
+ xml_type = xmlGetProp(node, "type");
+ if(xml_type)
+ {
+ type = g_strdup (xml_type);
+ xmlFree (xml_type);
+ }
+ else
{
type = g_strdup_printf("string");
}
Index: gnucash/src/engine/sixtp.c
diff -u gnucash/src/engine/sixtp.c:1.15 gnucash/src/engine/sixtp.c:1.16
--- gnucash/src/engine/sixtp.c:1.15 Tue Apr 17 04:32:04 2001
+++ gnucash/src/engine/sixtp.c Sat May 19 05:02:35 2001
@@ -751,7 +751,6 @@
char first_chunk[256];
char* cursor = NULL;
ssize_t num_read;
- char *tag_compare;
g_return_val_if_fail(filename, FALSE);
g_return_val_if_fail(first_tag, FALSE);
@@ -760,8 +759,6 @@
if (f == NULL)
return FALSE;
- tag_compare = g_strdup_printf("<%s>", first_tag);
-
num_read = fread(first_chunk, sizeof(char), sizeof(first_chunk) - 1, f);
fclose(f);
@@ -781,6 +778,9 @@
if(strncmp(cursor, "<?xml", 5) == 0)
{
+ char *tag_compare;
+ gboolean result;
+
if(!search_for('>', &cursor))
{
return FALSE;
@@ -791,18 +791,16 @@
return FALSE;
}
- if(strncmp(cursor, tag_compare, strlen(tag_compare)) == 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+ tag_compare = g_strdup_printf("<%s>", first_tag);
+
+ result = (strncmp(cursor, tag_compare, strlen(tag_compare)) == 0);
+ g_free (tag_compare);
+ return result;
}
else
{
return FALSE;
}
+
return FALSE;
}
Index: gnucash/src/gnome/window-acct-tree.c
diff -u gnucash/src/gnome/window-acct-tree.c:1.9 gnucash/src/gnome/window-acct-tree.c:1.10
--- gnucash/src/gnome/window-acct-tree.c:1.9 Tue May 1 03:42:13 2001
+++ gnucash/src/gnome/window-acct-tree.c Sat May 19 05:02:36 2001
@@ -126,6 +126,9 @@
gtk_label_set_text(GTK_LABEL(current), name);
}
gtk_label_set_justify(GTK_LABEL(current), GTK_JUSTIFY_LEFT);
+
+ if (name) free (name);
+
return current;
}
@@ -154,7 +157,8 @@
GNCMainInfo * maininfo = user_data;
GNCMainChildInfo * mc = g_new0(GNCMainChildInfo, 1);
GNCAcctTreeWin * win = gnc_acct_tree_window_new(child->name);
-
+ char * name;
+
mc->contents = gnc_acct_tree_window_get_widget(win);
mc->child = child;
mc->app = NULL;
@@ -166,10 +170,10 @@
gtk_object_set_user_data(GTK_OBJECT(child), mc);
- /* set the child name that will get used to save app state */
- gnome_mdi_child_set_name(mc->child,
- g_strdup_printf("gnc-acct-tree:id=%d",
- win->options_id));
+ /* set the child name that will get used to save app state */
+ name = g_strdup_printf("gnc-acct-tree:id=%d", win->options_id);
+ gnome_mdi_child_set_name(mc->child, name);
+ g_free (name);
gtk_signal_connect(GTK_OBJECT(child), "destroy",
gnc_acct_tree_view_destroy, mc);
@@ -974,8 +978,6 @@
SCM temp;
int options_id;
URLType type;
- char * location;
- char * label;
treewin->euro_change_callback_id =
gnc_register_option_change_callback(gnc_euro_change, treewin,
@@ -991,6 +993,9 @@
gnc_acct_tree_window_options_new(treewin);
}
else {
+ char * location = NULL;
+ char * label = NULL;
+
/* if an URL is specified, it should look like
* gnc-acct-tree:id=17 . We want to get the number out,
* then look up the options in the global DB. */
@@ -1014,8 +1019,11 @@
else {
gnc_acct_tree_window_options_new(treewin);
}
+
+ g_free (location);
+ g_free (label);
}
-
+
treewin->odb = gnc_option_db_new(treewin->options);
gtk_signal_connect(GTK_OBJECT(treewin->account_tree), "activate_account",