[PATCH] glib/gmem.c patch



Hi.

If glib is configured with `--enable-mem-check', g_free() never calls
free(). The below patch moves the free() call outside the #ifdef, and
takes a stab at not bombing if the pointer would be freed more than once.
The patch is against 1.3.2, but the code is basically the same in 1.2.8.

Perhaps this could go into 1.2.9? It might close of couple of bugs
pertaining to memory leaks listed in the gnome-bug page.

--- gmem.c.orig	Sun Oct  1 20:16:45 2000
+++ gmem.c	Mon Dec  4 15:00:55 2000
@@ -402,14 +402,16 @@
 #ifdef ENABLE_MEM_CHECK
       t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
       if (*t >= 1)
+      {
         g_warning ("freeing previously freed (%lu times) memory\n", *t);
+        return;
+      }
       *t += 1;
       mem = t;
       
       memset ((guchar*) mem + 2 * SIZEOF_LONG, 0, size);
-#else /* ENABLE_MEM_CHECK */
-      free (mem);
 #endif /* ENABLE_MEM_CHECK */
+      free (mem);
     }
 }
 

###############################
# Art Haas
# (713) 689-2417
###############################





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]