]> mj.ucw.cz Git - libucw.git/commitdiff
Added support for memory debuggers (efence and [untested] dmalloc), just
authorMartin Mares <mj@ucw.cz>
Mon, 11 Dec 2000 22:57:04 +0000 (22:57 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 11 Dec 2000 22:57:04 +0000 (22:57 +0000)
enable in the top-level Makefile.

All modules should use xmalloc/xrealloc/xfree (or memory pools) to allocate
their data. These functions automatically check for errors and they also
translate to dmalloc calls if needed.

lib/db-emul.c
lib/db.c
lib/fastbuf.c
lib/fb-mem.c
lib/lib.h
lib/pagecache.c
lib/pool.c
lib/regex.c

index a8d88743820800f87b95737342ef40bc638f0284..f988741e6c39f06cfc09ea6be4afe1eb207537e8 100644 (file)
@@ -39,7 +39,7 @@ sdbm_close(struct sdbm *d)
 {
   sdbm_rewind(d);
   gdbm_close(d->db);
-  free(d);
+  xfree(d);
 }
 
 static int
@@ -110,7 +110,7 @@ sdbm_fetch(struct sdbm *d, byte *key, uns keylen, byte *val, uns *vallen)
   if (!V.dptr)
     return 0;
   rc = sdbm_put_user(V.dptr, V.dsize, val, vallen);
-  free(V.dptr);
+  xfree(V.dptr);
   return rc ? SDBM_ERROR_TOO_LARGE : 1;
 }
 
@@ -119,7 +119,7 @@ sdbm_rewind(struct sdbm *d)
 {
   if (d->prevkey.dptr)
     {
-      free(d->prevkey.dptr);
+      xfree(d->prevkey.dptr);
       d->prevkey.dptr = NULL;
     }
 }
@@ -132,7 +132,7 @@ sdbm_get_next(struct sdbm *d, byte *key, uns *keylen, byte *val, uns *vallen)
   if (d->prevkey.dptr)
     {
       K = gdbm_nextkey(d->db, d->prevkey);
-      free(d->prevkey.dptr);
+      xfree(d->prevkey.dptr);
     }
   else
     K = gdbm_firstkey(d->db);
index 84eaef189c865bb4fc499480ebc28bf0b30fc9a0..46e6ba56b04f9c8fd7cf29a807455d332260a101 100644 (file)
--- a/lib/db.c
+++ b/lib/db.c
@@ -102,7 +102,7 @@ sdbm_close(struct sdbm *d)
     pgc_close(d->cache);
   if (d->fd >= 0)
     close(d->fd);
-  free(d);
+  xfree(d);
 }
 
 static uns
index 1be1b576b1f3696baf729bb92817d802f294d66f..0939b6d512533ad5bb9979b45eb3193a2b6879f8 100644 (file)
@@ -14,7 +14,7 @@ void bclose(struct fastbuf *f)
 {
   bflush(f);
   f->close(f);
-  free(f);
+  xfree(f);
 }
 
 void bflush(struct fastbuf *f)
index e83e2ebc69145c8f40c36fa8865f035470c8f738..2e0769a4642be8139e9094b086f160359f14dc26 100644 (file)
@@ -115,9 +115,9 @@ fbmem_close(struct fastbuf *f)
   while (b = m->first)
     {
       m->first = b->next;
-      free(b);
+      xfree(b);
     }
-  free(m);
+  xfree(m);
 }
 
 struct fastbuf *
index 2fb56d95e552a8a6a2beba1e9e3c5507a8174da1..7e4a3b562a9eeca9d791423d0cbe1e0c4a6a6586 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -74,8 +74,29 @@ void open_log_file(byte *);
 
 /* Allocation */
 
-void *xmalloc(uns);
-void *xrealloc(void *, uns);
+#ifdef DMALLOC
+/*
+ * The standard dmalloc macros tend to produce lots of namespace
+ * conflicts and we use only xmalloc and xfree, so we can define
+ * the stubs ourselves.
+ */
+#define DMALLOC_DISABLE
+#include <dmalloc.h>
+#define xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size)
+#define xrealloc(ptr,size) _xrealloc_leap(__FILE__, __LINE__, ptr, size)
+#define xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr)
+#else
+/*
+ * Unfortunately, several libraries we might want to link to define
+ * their own xmalloc and we don't want to interfere with them, hence
+ * the renaming.
+ */
+#define xmalloc bird_xmalloc
+void *xmalloc(unsigned);
+void *xrealloc(void *, unsigned);
+#define xfree(x) free(x)
+#endif
+
 byte *stralloc(byte *);
 
 /* Content-Type pattern matching and filters */
index 5acbca4b437e539a37faf813adc6908cc4eda145..e3257fe20e5a3612c92d6f80459784822614e56a 100644 (file)
@@ -65,8 +65,8 @@ pgc_close(struct page_cache *c)
   ASSERT(EMPTY_LIST(c->locked_pages));
   ASSERT(EMPTY_LIST(c->dirty_pages));
   ASSERT(EMPTY_LIST(c->free_pages));
-  free(c->hash_table);
-  free(c);
+  xfree(c->hash_table);
+  xfree(c);
 }
 
 static void
@@ -251,7 +251,7 @@ pgc_cleanup(struct page_cache *c)
       rem_node(&p->hn);
       c->free_count--;
       c->total_count--;
-      free(p);
+      xfree(p);
     }
   ASSERT(!c->free_count);
 }
index a7d6f5b0fd0b1c65faef6afe2d3fbc1efa5620f4..b4783e87c46bb7a24fbbd76faf4bf79c321adb08 100644 (file)
@@ -36,14 +36,14 @@ free_pool(struct mempool *p)
   for(d=p->first; d; d = c)
     {
       c = d->next;
-      free(d);
+      xfree(d);
     }
   for(d=p->first_large; d; d = c)
     {
       c = d->next;
-      free(d);
+      xfree(d);
     }
-  free(p);
+  xfree(p);
 }
 
 void
@@ -56,7 +56,7 @@ flush_pool(struct mempool *p)
   while (c = p->first_large)
     {
       p->first_large = c->next;
-      free(c);
+      xfree(c);
     }
 }
 
index d321172a603d564419028c4f5271a147ca894d0d..8cc9d2878d0994809a683d38af0335b3153167c3 100644 (file)
@@ -37,8 +37,8 @@ rx_compile(byte *p)
 void
 rx_free(regex *r)
 {
-  free(r->buf.buffer);
-  free(r);
+  xfree(r->buf.buffer);
+  xfree(r);
 }
 
 int