diff options
Diffstat (limited to 'xmlmemory.c')
| -rw-r--r-- | xmlmemory.c | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/xmlmemory.c b/xmlmemory.c index 927d078..4993351 100644 --- a/xmlmemory.c +++ b/xmlmemory.c @@ -29,6 +29,7 @@ #include <ctype.h> #endif +/* #define DEBUG_MEMORY */ /** * MEM_LIST: @@ -42,8 +43,8 @@ #endif #endif +#include <libxml/globals.h> /* must come before xmlmemory.h */ #include <libxml/xmlmemory.h> -#include <libxml/globals.h> #include <libxml/xmlerror.h> #include <libxml/threads.h> @@ -60,7 +61,7 @@ void xmlMallocBreakpoint(void); * * ************************************************************************/ - +#if !defined(LIBXML_THREAD_ENABLED) && !defined(LIBXML_THREAD_ALLOC_ENABLED) #ifdef xmlMalloc #undef xmlMalloc #endif @@ -70,7 +71,7 @@ void xmlMallocBreakpoint(void); #ifdef xmlMemStrdup #undef xmlMemStrdup #endif - +#endif /* * Each of the blocks allocated begin with a header containing informations @@ -309,6 +310,9 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line) { MEMHDR *p; unsigned long number; +#ifdef DEBUG_MEMORY + size_t oldsize; +#endif if (ptr == NULL) return(xmlMallocLoc(size, file, line)); @@ -325,6 +329,9 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line) p->mh_tag = ~MEMTAG; xmlMutexLock(xmlMemMutex); debugMemSize -= p->mh_size; +#ifdef DEBUG_MEMORY + oldsize = p->mh_size; +#endif #ifdef MEM_LIST debugmem_list_delete(p); #endif @@ -356,6 +363,10 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line) TEST_POINT +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "Realloced(%d to %d) Ok\n", oldsize, size); +#endif return(HDR_2_CLIENT(p)); error: @@ -388,6 +399,9 @@ xmlMemFree(void *ptr) { MEMHDR *p; char *target; +#ifdef DEBUG_MEMORY + size_t size; +#endif if (ptr == (void *) -1) { xmlGenericError(xmlGenericErrorContext, @@ -414,6 +428,9 @@ xmlMemFree(void *ptr) memset(target, -1, p->mh_size); xmlMutexLock(xmlMemMutex); debugMemSize -= p->mh_size; +#ifdef DEBUG_MEMORY + size = p->mh_size; +#endif #ifdef MEM_LIST debugmem_list_delete(p); #endif @@ -423,6 +440,11 @@ xmlMemFree(void *ptr) TEST_POINT +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "Freed(%d) Ok\n", size); +#endif + return; error: @@ -618,12 +640,15 @@ xmlMemDisplay(FILE *fp) switch (p->mh_type) { case STRDUP_TYPE:fprintf(fp,"strdup() in ");break; case MALLOC_TYPE:fprintf(fp,"malloc() in ");break; - case REALLOC_TYPE:fprintf(fp,"realloc() in ");break; + case REALLOC_TYPE:fprintf(fp,"realloc() in ");break; case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break; - case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break; - default:fprintf(fp," ??? in ");break; + case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break; + default: + fprintf(fp,"Unknow memory block, corruped maybe"); + xmlMutexUnlock(xmlMemMutex); + return; } - if (p->mh_file != NULL) fprintf(fp,"%s(%d)", p->mh_file, p->mh_line); + if (p->mh_file != NULL) fprintf(fp,"%s(%d)", p->mh_file, p->mh_line); if (p->mh_tag != MEMTAG) fprintf(fp," INVALID"); nb++; @@ -780,6 +805,10 @@ xmlMemoryDump(void) int xmlInitMemory(void) { +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlInitMemory()\n"); +#endif #ifdef HAVE_STDLIB_H char *breakpoint; #endif @@ -808,7 +837,6 @@ xmlInitMemory(void) xmlGenericError(xmlGenericErrorContext, "xmlInitMemory() Ok\n"); #endif - return(0); } @@ -819,12 +847,20 @@ xmlInitMemory(void) */ void xmlCleanupMemory(void) { +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlCleanupMemory()\n"); +#endif if (xmlMemInitialized == 0) return; xmlFreeMutex(xmlMemMutex); xmlMemMutex = NULL; xmlMemInitialized = 0; +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlCleanupMemory() Ok\n"); +#endif } /** @@ -845,6 +881,10 @@ xmlCleanupMemory(void) { int xmlMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc) { +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlMemSetup()\n"); +#endif if (freeFunc == NULL) return(-1); if (mallocFunc == NULL) @@ -858,6 +898,10 @@ xmlMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocAtomic = mallocFunc; xmlRealloc = reallocFunc; xmlMemStrdup = strdupFunc; +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlMemSetup() Ok\n"); +#endif return(0); } @@ -904,6 +948,10 @@ int xmlGcMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocFunc mallocAtomicFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc) { +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlGcMemSetup()\n"); +#endif if (freeFunc == NULL) return(-1); if (mallocFunc == NULL) @@ -919,6 +967,10 @@ xmlGcMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocAtomic = mallocAtomicFunc; xmlRealloc = reallocFunc; xmlMemStrdup = strdupFunc; +#ifdef DEBUG_MEMORY + xmlGenericError(xmlGenericErrorContext, + "xmlGcMemSetup() Ok\n"); +#endif return(0); } |
