OSDN Git Service

A patch from Matthias Kilian <kili@outback.escape.de> to fix -DDEBUG_MALLOC
authorEric Andersen <andersen@codepoet.org>
Fri, 11 May 2001 16:25:55 +0000 (16:25 -0000)
committerEric Andersen <andersen@codepoet.org>
Fri, 11 May 2001 16:25:55 +0000 (16:25 -0000)
so that it works for realloc too.
 -Erik

include/stdlib.h
libc/stdlib/malloc/Makefile
libc/stdlib/malloc/alloc.c

index 4f225aa..cdb3e8f 100644 (file)
@@ -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
 
index d4d2789..c2190dc 100644 (file)
@@ -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 \
index 4988bb0..a521cf2 100644 (file)
@@ -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