Update of /cvsroot/monetdb/MonetDB/src/gdk
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2814/src/gdk

Modified Files:
        gdk_align.mx gdk_bat.mx gdk_heap.mx gdk_search.mx 
        gdk_storage.mx gdk_utils.mx 
Log Message:
fixed heap leak (copy/paste htype/ttype problem). It leaked both on 
disk and in (virtual) memory. 

Used valgrind to debug GDKmmap/GDKmunmap leaks. This requires an include
file from valgrind (license wise okay). The extra calls are only done with 
NDEBUG not set (ie with disable-assert).

added lots of asserts for this.


Index: gdk_search.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_search.mx,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- gdk_search.mx       11 Jan 2008 10:37:00 -0000      1.74
+++ gdk_search.mx       13 Jan 2008 13:45:46 -0000      1.75
@@ -388,7 +388,7 @@
                        if (h)
                                GDKfree(h);
                        /* create the hash structures */
-                       hp = (Heap *) GDKmalloc(sizeof(Heap));
+                       hp = (Heap *) GDKzalloc(sizeof(Heap));
                        hp->filename = GDKmalloc(strlen(nme) + 12);
                        sprintf(hp->filename, "%s.%chash", nme, b->batCacheid > 
0 ? 'h' : 't');
                        if ((h = HASHnew(hp, ATOMtype(b->htype), 
BATcapacity(b), (size_t) mask)) == NULL) {

Index: gdk_utils.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_utils.mx,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- gdk_utils.mx        11 Jan 2008 10:37:01 -0000      1.204
+++ gdk_utils.mx        13 Jan 2008 13:45:46 -0000      1.205
@@ -42,20 +42,8 @@
 @c
 #include "monetdb_config.h"
 
-#ifndef GDK_NOLINK
 #include "gdk.h"
 
-#else /* GDK_NOLINK */
-
-#undef GDKmalloc
-#undef GDKrealloc
-#undef GDKfree
-
-#define GDKmalloc(size)        malloc(size)
-#define GDKrealloc(buf,size)   realloc(buf,size)
-#define GDKfree(buf)   free(buf)
-#endif
-
 int gdk_alloc_map = 1;
 char GDKdbfarmStr[PATHLENGTH] = { "dbfarm" };
 char GDKdbnameStr[PATHLENGTH] = { 0 };
@@ -88,6 +76,15 @@
 #ifdef NATIVE_WIN32
 #define chdir _chdir
 #endif
+
+#ifdef NDEBUG
+#ifndef NVALGRIND
+#define NVALGRIND NDEBUG
+#endif
+#endif
+
+#include <valgrind.h>
+
 @}
 @+ Monet configuration file
 Parse a possible MonetDB.conf file (either in the default location
@@ -1263,6 +1260,8 @@
                }
        }
        if (ret != (void *) -1L) {
+               /* since mmap directly have content we say its zero-ed memory */
+               VALGRIND_MALLOCLIKE_BLOCK(ret, len, 0, 1);
                MT_alloc_register(ret, len, 'M');
                GDKvminc(len);
        }
@@ -1276,6 +1275,7 @@
 
        MT_alloc_register(addr, size, 'm');
        ret = MT_munmap(addr, size);
+       VALGRIND_FREELIKE_BLOCK(addr, 0);
        if (ret == 0) {
                @:memdec(0,size,"GDKunmap")@
        }

Index: gdk_align.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_align.mx,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- gdk_align.mx        11 Jan 2008 10:36:59 -0000      1.88
+++ gdk_align.mx        13 Jan 2008 13:45:46 -0000      1.89
@@ -684,6 +684,7 @@
 void
 VIEWdestroy(BAT *b)
 {
+       assert(isVIEW(b));
        VIEWunlink(b);
        b->H->heap.base = NULL;
        b->H->heap.filename = NULL;

Index: gdk_heap.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_heap.mx,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- gdk_heap.mx 11 Jan 2008 10:37:00 -0000      1.91
+++ gdk_heap.mx 13 Jan 2008 13:45:46 -0000      1.92
@@ -221,6 +221,7 @@
                                fclose(fp);
                                /* a non-persistent heap: we create a .priv but 
*not* MMAP_PRIV !!! */
                                h->storage = STORE_MMAP;
+                               h->base = NULL;
                                if (HEAPload(h, nme, ext, FALSE) >= 0) {
                                        memcpy(h->base, bak.base, bak.free);
                                        HEAPfree(&bak);
@@ -414,6 +415,7 @@
        char ext2[64];
 
        if (h->size <= 0) {
+               assert(h->base == 0);
                return 0;
        }
        if (h->base) {

Index: gdk_storage.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_storage.mx,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -d -r1.132 -r1.133
--- gdk_storage.mx      11 Jan 2008 10:37:00 -0000      1.132
+++ gdk_storage.mx      13 Jan 2008 13:45:46 -0000      1.133
@@ -730,7 +730,6 @@
        bat bid = ABS(b->batCacheid);
        str o = BBP_physical(bid);
        BAT *loaded = BBP_cache(bid);
-       int vv = (!b->htype && !b->ttype);
 
        if (loaded) {
                b = loaded;
@@ -750,14 +749,14 @@
                if (b->htype != TYPE_void && HEAPdelete(&b->H->heap, o, "head") 
&&
                    b->batCopiedtodisk)
                        GDKwarning("BATdelete(%s): bun heap\n", BATgetId(b));
-       } else if (b->H->heap.base && !vv) {
+       } else if (b->H->heap.base) {
                HEAPfree(&b->H->heap);
        }
        if (b->batCopiedtodisk || (b->T->heap.storage & STORE_MMAP)) {
-               if (b->htype != TYPE_void && HEAPdelete(&b->T->heap, o, "tail") 
&&
+               if (b->ttype != TYPE_void && HEAPdelete(&b->T->heap, o, "tail") 
&&
                    b->batCopiedtodisk)
                        GDKwarning("BATdelete(%s): bun heap\n", BATgetId(b));
-       } else if (b->T->heap.base && !vv) {
+       } else if (b->T->heap.base) {
                HEAPfree(&b->T->heap);
        }
        if (b->hheap) {

Index: gdk_bat.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_bat.mx,v
retrieving revision 1.185
retrieving revision 1.186
diff -u -d -r1.185 -r1.186
--- gdk_bat.mx  11 Jan 2008 10:36:59 -0000      1.185
+++ gdk_bat.mx  13 Jan 2008 13:45:46 -0000      1.186
@@ -437,6 +437,7 @@
                size_t cap = 0;
 
                hh.filename = th.filename = NULL;
+               hh.base = th.base = NULL;
                if (b->H->vheap && b->H->vheap->free > 0) {
                        if (ATOMheap(b->htype, &hh, cap) < 0)
                                return NULL;
@@ -501,8 +502,12 @@
        HASHdestroy(b);
        if (b->htype)
                HEAPfree(&b->H->heap);
+       else
+               assert(!b->H->heap.base);
        if (b->ttype)
                HEAPfree(&b->T->heap);
+       else
+               assert(!b->T->heap.base);
        if (b->H->vheap) 
                HEAPfree(b->H->vheap);
        if (b->T->vheap) 
@@ -3058,7 +3063,7 @@
                        q = yy + lim;
                        if (p < q) {
                                BAT *bv = VIEWcreate(b, b);
-                               Heap *hp = (Heap *) GDKmalloc(sizeof(Heap));
+                               Heap *hp = (Heap *) GDKzalloc(sizeof(Heap));
                                str nme = BBP_physical(bv->batCacheid);
 
                                hp->filename = GDKmalloc(strlen(nme) + 12);


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to