GNOME Bugzilla – Bug 564890
lib/persistence.c:167: Memory leak: integer
Last modified: 2009-01-20 23:29:33 UTC
In file lib/persistence.c:167: Variable integer leaks memory printf() is executed. It might also leak when insert() is called, depending on how hash table was created. I don't know the code well enough to comment that, but at least with the printf you will leak memory. attr = composite_find_attribute(node, "intvalue"); if (attr != NULL) { integer = g_new(gint, 1); *integer = data_int(attribute_first_data(attr)); } else return; if (g_hash_table_lookup(persistent_integers, role) == NULL) g_hash_table_insert(persistent_integers, role, integer); else printf("Int %s registered before loading persistence!\n", role); This bug was found using cppcheck: http://cppcheck.wiki.sourceforge.net/
These two variables have the same problem: lib/persistence.c:187: Memory leak: realval lib/persistence.c:207: Memory leak: booleanval
This is not an unbound leak. It is more a static allocation which gets released by the OS at programs end. (It is similar to every type ever registered with GObject).
You are probably right about GObject part, but I think you missed the point about printf() line. If "Int %s registered before loading persistence!\n" is printed, variable "integer" is not used or released at all. I think you need something like this (or move the g_hash_table_lookup() call above the g_new() call and don't allocate memory at all if lookup gives value that is not null. Index: lib/persistence.c =================================================================== --- lib/persistence.c (revision 4192) +++ lib/persistence.c (working copy) @@ -162,8 +162,10 @@ if (g_hash_table_lookup(persistent_integers, role) == NULL) g_hash_table_insert(persistent_integers, role, integer); - else + else { printf("Int %s registered before loading persistence!\n", role); + g_free(integer); + } } static void
your are right about what I#ve missed ;) Pathological case but still.
2009-01-20 Hans Breuer <hans@breuer.org> * lib/persistence.c : use g_warning() instead of printf() for pathological cases, also don't leak memory than; bug #564890.