From 35ac83374e2a5fca718f6ab35d666560fa50429c Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sun, 11 Mar 2012 21:55:53 +0000 Subject: [PATCH] Replace g_list_append by g_list_prepend to increase performance. To my surprise, this apparently also fixes a memory leak, but I don't know why. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22074 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/libqof/qof/qofobject.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libqof/qof/qofobject.c b/src/libqof/qof/qofobject.c index d1a83e6080..c1d1141923 100644 --- a/src/libqof/qof/qofobject.c +++ b/src/libqof/qof/qofobject.c @@ -226,10 +226,10 @@ qof_object_foreach (QofIdTypeConst type_name, QofBook *book, } static void -do_append (QofInstance *qof_p, gpointer list_p) +do_prepend (QofInstance *qof_p, gpointer list_p) { GList **list = list_p; - *list = g_list_append(*list, qof_p); + *list = g_list_prepend(*list, qof_p); } void @@ -238,7 +238,7 @@ qof_object_foreach_sorted (QofIdTypeConst type_name, QofBook *book, QofInstanceF GList *list = NULL; GList *iter; - qof_object_foreach(type_name, book, do_append, &list); + qof_object_foreach(type_name, book, do_prepend, &list); list = g_list_sort(list, qof_instance_guid_compare); @@ -248,6 +248,13 @@ qof_object_foreach_sorted (QofIdTypeConst type_name, QofBook *book, QofInstanceF } g_list_free(list); + + // FIXME: Apparently this is a memory leak, as this g_list_free doesn't + // free all of the allocated memory of g_list_append in do_append(). Why?!? + // Does g_list_sort have special side-effects on the memory of the list? + // Subsequently, I've changed the g_list_append into g_list_prepend, but + // solely for performance reasons. To my surprise, this also makes the + // dubious memory leak go away. But again why?!? } const char *