summaryrefslogtreecommitdiff
path: root/src/util/Malloc.c
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2001-03-30 12:13:04 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2001-03-30 12:13:04 +0000
commitb2f955ffde1b42c13bae47d3aaad6f5940e0423a (patch)
tree6de021dfeb4f13115e76d36684fdda5f332c7720 /src/util/Malloc.c
parent35922d88cacb7cde158ab128bcaaf13fca8a5c50 (diff)
Fixed bug in CCTKi_Realloc().
Invalidate magic number before freeing a memory block so that we really catch externally malloc'ed stuff which got such a block only by accident. git-svn-id: http://svn.cactuscode.org/flesh/trunk@2087 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util/Malloc.c')
-rw-r--r--src/util/Malloc.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/util/Malloc.c b/src/util/Malloc.c
index cfd1da6c..4f2f0027 100644
--- a/src/util/Malloc.c
+++ b/src/util/Malloc.c
@@ -20,7 +20,7 @@
#include "StoreHandledData.h"
-/*$#define MEMDEBUG$*/
+/* #define MEMDEBUG 1 */
/* Undefine malloc */
#if defined(malloc)
@@ -210,6 +210,12 @@ void *CCTKi_Realloc(void *pointer, size_t size, int line, const char *file)
}
else
{
+ /* update some static variables */
+ /* must be done before reallocation since the info pointer
+ will be invalid afterwards */
+ pastmem = totmem;
+ totmem = totmem - info->size + size;
+
/* reallocate starting at info pointer */
data = (char*)realloc(info, size+sizeof(t_mallocinfo));
if (!data)
@@ -220,10 +226,6 @@ void *CCTKi_Realloc(void *pointer, size_t size, int line, const char *file)
/*$CCTK_Abort(NULL);$*/
}
- /* update some static variables */
- pastmem = totmem;
- totmem = totmem - info->size + size;
-
/* and update */
info = (t_mallocinfo*) data;
info->size = size;
@@ -312,6 +314,10 @@ void CCTKi_Free(void *pointer, int line, const char *file)
info->size, info->file, info->line, CCTK_TotalMemory());
#endif
+ /* invalidate the magic number so that we catch things
+ which were malloc'ed externally and got a CCTKi_Free'ed block
+ by accident */
+ info->ok = 0;
free(info);
}
}