Browse Source

A patch from Matthias Kilian <kili@outback.escape.de> to fix -DDEBUG_MALLOC
so that it works for realloc too.
-Erik

Eric Andersen 23 years ago
parent
commit
9b39f1ce89
3 changed files with 13 additions and 2 deletions
  1. 1 1
      include/stdlib.h
  2. 1 1
      libc/stdlib/malloc/Makefile
  3. 11 0
      libc/stdlib/malloc/alloc.c

+ 1 - 1
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
 

+ 1 - 1
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 \

+ 11 - 0
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