summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-11 16:25:55 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-11 16:25:55 +0000
commit9b39f1ce8980202bcd9db6be04b462e766d7d91c (patch)
treedfbf6d1253feb46f2b9730c33394dd5dbcea19f7
parent007b8e2060ccae6159a36c52db42d04b13fa2b6f (diff)
A patch from Matthias Kilian <kili@outback.escape.de> to fix -DDEBUG_MALLOC
so that it works for realloc too. -Erik
-rw-r--r--include/stdlib.h2
-rw-r--r--libc/stdlib/malloc/Makefile2
-rw-r--r--libc/stdlib/malloc/alloc.c11
3 files changed, 13 insertions, 2 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index 4f225aacc..cdb3e8fee 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -80,7 +80,7 @@ extern __ptr_t realloc_dbg __P ((__ptr_t, size_t, char* func, char* file, int li
extern void free_dbg __P ((__ptr_t, char* func, char* file, int line));
#define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
#define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
-#define realloc(x) realloc((x),__FUNCTION__,__FILE__,__LINE__)
+#define realloc(x,y) realloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
#define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
#endif
diff --git a/libc/stdlib/malloc/Makefile b/libc/stdlib/malloc/Makefile
index d4d278949..c2190dcdc 100644
--- a/libc/stdlib/malloc/Makefile
+++ b/libc/stdlib/malloc/Makefile
@@ -25,7 +25,7 @@ include $(TOPDIR)Rules.mak
LIBC=$(TOPDIR)libc.a
MSRC=alloc.c
-MOBJ=malloc_dbg.o free_dbg.o calloc_dbg.o
+MOBJ=malloc_dbg.o free_dbg.o calloc_dbg.o realloc_dbg.o
MSRC1=malloc.c
MOBJ1=_avl_support.o _free_support.o _malloc_init.o _realloc_no_move.o calloc.o \
diff --git a/libc/stdlib/malloc/alloc.c b/libc/stdlib/malloc/alloc.c
index 4988bb055..a521cf2e8 100644
--- a/libc/stdlib/malloc/alloc.c
+++ b/libc/stdlib/malloc/alloc.c
@@ -47,3 +47,14 @@ void free_dbg(void *ptr, char *function, char *file, int line)
}
#endif
+
+#ifdef L_realloc_dbg
+void *realloc_dbg(void *ptr, size_t size, char *function, char *file, int line)
+{
+ fprintf(stderr, "realloc of %p to %ld bytes at %s @%s;%d = ", ptr,
+ size, function, file, line);
+ ptr = realloc(ptr, size);
+ fprintf(stderr, "%p\n", ptr);
+ return ptr;
+}
+#endif