malloc debugging for flex
authorMarko Kreen <markokr@gmail.com>
Mon, 29 Oct 2007 19:57:59 +0000 (19:57 +0000)
committerMarko Kreen <markokr@gmail.com>
Mon, 29 Oct 2007 19:57:59 +0000 (19:57 +0000)
Makefile
src/dbgmalloc.h [new file with mode: 0644]

index c2521e15bf25fc4c6ef4ed54ae1b70e19670f697..61d4922474402e748cac08ca736cc20f00e049f7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,8 @@ SHLIB_LINK = -L$(PQLIB) -lpq
 
 DIST_FILES = Makefile src/plproxy.h src/rowstamp.h src/scanner.l src/parser.y \
             sql/*.sql expected/*.out config/*.sql doc/*.txt doc/Makefile \
-            AUTHORS COPYRIGHT README plproxy.sql.in NEWS debian/packages
+            AUTHORS COPYRIGHT README plproxy.sql.in NEWS debian/packages \
+                src/dbgmalloc.h
 DIST_DIRS = src sql expected config doc debian
 TARNAME = plproxy-$(PLPROXY_VERSION)
 
@@ -45,7 +46,7 @@ src/scanner.c: src/scanner.l
        cd src; $(FLEX) -oscanner.c scanner.l
 
 # dependencies
-$(OBJS): src/plproxy.h src/rowstamp.h
+$(OBJS): src/plproxy.h src/rowstamp.h src/dbgmalloc.h
 
 # utility rules
 
diff --git a/src/dbgmalloc.h b/src/dbgmalloc.h
new file mode 100644 (file)
index 0000000..1f6caf8
--- /dev/null
@@ -0,0 +1,28 @@
+
+#define MALLOCLOGx
+
+static inline void *my_malloc(const char *pfx, int len) {
+       void *p = palloc(len);
+#ifdef MALLOCLOG
+       elog(NOTICE, "%s:%s(%d) = %p", pfx, __FUNCTION__, len, p);
+#endif
+       return p;
+}
+static inline void *my_realloc(const char *pfx, void *old, int len) {
+       void *p = repalloc(old, len);
+#ifdef MALLOCLOG
+       elog(NOTICE, "%s:%s(%p, %d) = %p", pfx, __FUNCTION__, old, len, p);
+#endif
+       return p;
+}
+static inline void my_free(const char *pfx, void *p) {
+       pfree(p);
+#ifdef MALLOCLOG
+       elog(NOTICE, "%s:%s(%p)", pfx, __FUNCTION__, p);
+#endif
+}
+
+#define malloc(x)  my_malloc(__FILE__, x)
+#define realloc(x, y)  my_realloc(__FILE__, x, y)
+#define free(x)  my_free(__FILE__, x)
+