diff --git a/Makefile b/Makefile index c2521e1..61d4922 100644 --- 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 index 0000000..1f6caf8 --- /dev/null +++ b/src/dbgmalloc.h @@ -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) +