#include <stdio.h>
#include <libxml/xmlversion.h>
#include <libxml/threads.h>
#include <libxml/globals.h>
Go to the source code of this file.
|
XMLPUBFUN int XMLCALL | xmlMemSetup (xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc) |
|
XMLPUBFUN int XMLCALL | xmlMemGet (xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc) |
|
XMLPUBFUN int XMLCALL | xmlGcMemSetup (xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocFunc mallocAtomicFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc) |
|
XMLPUBFUN int XMLCALL | xmlGcMemGet (xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlMallocFunc *mallocAtomicFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc) |
|
XML_DEPRECATED XMLPUBFUN int XMLCALL | xmlInitMemory (void) |
|
XML_DEPRECATED XMLPUBFUN void XMLCALL | xmlCleanupMemory (void) |
|
XMLPUBFUN int XMLCALL | xmlMemUsed (void) |
|
XMLPUBFUN int XMLCALL | xmlMemBlocks (void) |
|
XMLPUBFUN void XMLCALL | xmlMemDisplay (FILE *fp) |
|
XMLPUBFUN void XMLCALL | xmlMemDisplayLast (FILE *fp, long nbBytes) |
|
XMLPUBFUN void XMLCALL | xmlMemShow (FILE *fp, int nr) |
|
XMLPUBFUN void XMLCALL | xmlMemoryDump (void) |
|
XMLPUBFUN void *XMLCALL | xmlMemMalloc (size_t size) LIBXML_ATTR_ALLOC_SIZE(1) |
|
XMLPUBFUN void *XMLCALL | xmlMemRealloc (void *ptr, size_t size) |
|
XMLPUBFUN void XMLCALL | xmlMemFree (void *ptr) |
|
XMLPUBFUN char *XMLCALL | xmlMemoryStrdup (const char *str) |
|
XMLPUBFUN void *XMLCALL | xmlMallocLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1) |
|
XMLPUBFUN void *XMLCALL | xmlReallocLoc (void *ptr, size_t size, const char *file, int line) |
|
XMLPUBFUN void *XMLCALL | xmlMallocAtomicLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1) |
|
XMLPUBFUN char *XMLCALL | xmlMemStrdupLoc (const char *str, const char *file, int line) |
|
◆ LIBXML_ATTR_ALLOC_SIZE
xmlMallocFunc: @size: the size requested in bytes
Signature for a malloc() implementation.
Returns a pointer to the newly allocated block or NULL in case of error.
Definition at line 66 of file xmlmemory.h.
◆ xmlFreeFunc
DEBUG_MEMORY:
DEBUG_MEMORY replaces the allocator with a collect and debug shell to the libc allocator. DEBUG_MEMORY should only be activated when debugging libxml i.e. if libxml has been configured with –with-debug-mem too.DEBUG_MEMORY_LOCATION:
DEBUG_MEMORY_LOCATION should be activated only when debugging libxml i.e. if libxml has been configured with –with-debug-mem too.xmlFreeFunc: @mem: an already allocated block of memory
Signature for a free() implementation.
Definition at line 57 of file xmlmemory.h.
◆ xmlReallocFunc
xmlReallocFunc: @mem: an already allocated block of memory @size: the new size requested in bytes
Signature for a realloc() implementation.
Returns a pointer to the newly reallocated block or NULL in case of error.
Definition at line 77 of file xmlmemory.h.
◆ xmlStrdupFunc
xmlStrdupFunc: @str: a zero terminated string
Signature for an strdup() implementation.
Returns the copy of the string or NULL in case of error.
Definition at line 87 of file xmlmemory.h.
◆ xmlCleanupMemory()
xmlCleanupMemory:
DEPRECATED: This function will be made private. Call xmlCleanupParser to free global state but see the warnings there. xmlCleanupParser should be only called once at program exit. In most cases, you don't have call cleanup functions at all.
Free up all the memory allocated by the library for its own use. This should not be called by user level code.
Definition at line 989 of file xmlmemory.c.
992 "xmlCleanupMemory()\n");
1002 "xmlCleanupMemory() Ok\n");
static int xmlMemInitialized
static xmlMutexPtr xmlMemMutex
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
XMLPUBFUN void XMLCALL xmlFreeMutex(xmlMutexPtr tok)
XMLPUBVAR void * xmlGenericErrorContext
Referenced by xmlCleanupParser().
◆ xmlGcMemGet()
xmlGcMemGet: @freeFunc: place to save the free() function in use @mallocFunc: place to save the malloc() function in use @mallocAtomicFunc: place to save the atomic malloc() function in use @reallocFunc: place to save the realloc() function in use @strdupFunc: place to save the strdup() function in use
Provides the memory access functions set currently in use The mallocAtomicFunc is specialized for atomic block allocations (i.e. of areas useful for garbage collected memory allocators
Returns 0 on success
Definition at line 1132 of file xmlmemory.c.
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
XMLPUBVAR xmlReallocFunc xmlRealloc
XMLPUBVAR xmlFreeFunc xmlFree
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
XMLPUBVAR xmlMallocFunc xmlMalloc
◆ xmlGcMemSetup()
xmlGcMemSetup: @freeFunc: the free() function to use @mallocFunc: the malloc() function to use @mallocAtomicFunc: the malloc() function to use for atomic allocations @reallocFunc: the realloc() function to use @strdupFunc: the strdup() function to use
Override the default memory access functions with a new set This has to be called before any other libxml routines ! The mallocAtomicFunc is specialized for atomic block allocations (i.e. of areas useful for garbage collected memory allocators
Should this be blocked if there was already some allocations done ?
Returns 0 on success
Definition at line 1088 of file xmlmemory.c.
1093 "xmlGcMemSetup()\n");
1095 if (freeFunc ==
NULL)
1097 if (mallocFunc ==
NULL)
1099 if (mallocAtomicFunc ==
NULL)
1101 if (reallocFunc ==
NULL)
1103 if (strdupFunc ==
NULL)
1112 "xmlGcMemSetup() Ok\n");
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
XMLPUBVAR xmlReallocFunc xmlRealloc
XMLPUBVAR xmlFreeFunc xmlFree
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
XMLPUBVAR xmlMallocFunc xmlMalloc
XMLPUBVAR void * xmlGenericErrorContext
◆ xmlInitMemory()
xmlInitMemory:
DEPRECATED: This function will be made private. Call xmlInitParser to initialize the library.
Initialize the memory layer.
Returns 0 on success
Definition at line 946 of file xmlmemory.c.
951 "xmlInitMemory()\n");
972 "xmlInitMemory() Ok\n");
static int xmlMemInitialized
static void * xmlMemTraceBlockAt
static xmlMutexPtr xmlMemMutex
static unsigned int xmlMemStopAtBlock
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
XMLPUBFUN xmlMutexPtr XMLCALL xmlNewMutex(void)
XMLPUBVAR void * xmlGenericErrorContext
Referenced by xmlInitParser(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemStrdupLoc(), and xmlReallocLoc().
◆ xmlMallocAtomicLoc()
Definition at line 221 of file xmlmemory.c.
229 "Malloc(%d)\n",
size);
236 "xmlMallocAtomicLoc : Unsigned overflow\n");
245 "xmlMallocAtomicLoc : Out of free space\n");
260 debugmem_list_add(
p);
266 "Malloc(%d) Ok\n",
size);
276 (
long unsigned)
size);
static unsigned int block
static int xmlMemInitialized
static void * xmlMemTraceBlockAt
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
static unsigned int xmlMemStopAtBlock
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
static unsigned long debugMemBlocks
void xmlMallocBreakpoint(void)
static unsigned long debugMaxMemSize
#define MALLOC_ATOMIC_TYPE
XMLPUBVAR void * xmlGenericErrorContext
◆ xmlMallocLoc()
Definition at line 145 of file xmlmemory.c.
153 "Malloc(%d)\n",
size);
160 "xmlMallocLoc : Unsigned overflow\n");
169 "xmlMallocLoc : Out of free space\n");
184 debugmem_list_add(
p);
190 "Malloc(%d) Ok\n",
size);
200 (
long unsigned)
size);
static unsigned int block
static int xmlMemInitialized
static void * xmlMemTraceBlockAt
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
static unsigned int xmlMemStopAtBlock
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
static unsigned long debugMemBlocks
void xmlMallocBreakpoint(void)
static unsigned long debugMaxMemSize
XMLPUBVAR void * xmlGenericErrorContext
Referenced by xmlMemMalloc(), and xmlReallocLoc().
◆ xmlMemBlocks()
xmlMemBlocks:
Provides the number of memory areas currently allocated
Returns an int representing the number of blocks
Definition at line 586 of file xmlmemory.c.
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
static unsigned long debugMemBlocks
◆ xmlMemDisplay()
xmlMemDisplay: @fp: a FILE descriptor used as the output file, if NULL, the result is written to the file .memorylist
show in-extenso the memory blocks allocated
Definition at line 739 of file xmlmemory.c.
752 fp =
fopen(
".memorylist",
"w");
764 fprintf(fp,
" MEMORY ALLOCATED : %lu, MAX was %lu\n",
766 fprintf(fp,
"BLOCK NUMBER SIZE TYPE\n");
772 (
unsigned long)
p->mh_size);
773 switch (
p->mh_type) {
780 fprintf(fp,
"Unknown memory block, may be corrupted");
786 if (
p->mh_file !=
NULL)
fprintf(fp,
"%s(%u)",
p->mh_file,
p->mh_line);
791 xmlMemContentShow(fp,
p);
800 fprintf(fp,
"Memory list not compiled (MEM_LIST not defined !)\n");
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
#define REALLOC_ATOMIC_TYPE
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
GLenum GLuint GLenum GLsizei const GLchar * buf
static xmlMutexPtr xmlMemMutex
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
size_t CDECL strftime(char *str, size_t max, const char *format, const struct tm *mstm)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
static unsigned long debugMaxMemSize
#define MALLOC_ATOMIC_TYPE
Referenced by debugmem_tag_error(), and xmlMemoryDump().
◆ xmlMemDisplayLast()
xmlMemDisplayLast: @fp: a FILE descriptor used as the output file, if NULL, the result is written to the file .memorylist @nbBytes: the amount of memory to dump
the last nbBytes of memory allocated and not freed, useful for dumping the memory left allocated between two places at runtime.
Definition at line 668 of file xmlmemory.c.
681 fp =
fopen(
".memorylist",
"w");
687 fprintf(fp,
" Last %li MEMORY ALLOCATED : %lu, MAX was %lu\n",
689 fprintf(fp,
"BLOCK NUMBER SIZE TYPE\n");
693 while ((
p) && (nbBytes > 0)) {
695 (
unsigned long)
p->mh_size);
696 switch (
p->mh_type) {
703 fprintf(fp,
"Unknown memory block, may be corrupted");
709 if (
p->mh_file !=
NULL)
fprintf(fp,
"%s(%u)",
p->mh_file,
p->mh_line);
714 xmlMemContentShow(fp,
p);
719 nbBytes -= (
unsigned long)
p->mh_size;
724 fprintf(fp,
"Memory list not compiled (MEM_LIST not defined !)\n");
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
#define REALLOC_ATOMIC_TYPE
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static unsigned long debugMaxMemSize
#define MALLOC_ATOMIC_TYPE
◆ xmlMemFree()
xmlMemFree: @ptr: the memory block pointer
a free() equivalent, with error checking.
Definition at line 414 of file xmlmemory.c.
425 if (
ptr == (
void *) -1) {
427 "trying to free pointer from freed area\n");
456 debugmem_list_delete(
p);
466 "Freed(%d) Ok\n",
size);
473 "xmlMemFree(%p) error\n",
ptr);
static void * xmlMemTraceBlockAt
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
static unsigned int xmlMemStopAtBlock
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
static unsigned long debugMemBlocks
void xmlMallocBreakpoint(void)
XMLPUBVAR void * xmlGenericErrorContext
Referenced by myFreeFunc(), myMallocFunc(), myReallocFunc(), and xmlInitializeGlobalState().
◆ xmlMemGet()
xmlMemGet: @freeFunc: place to save the free() function in use @mallocFunc: place to save the malloc() function in use @reallocFunc: place to save the realloc() function in use @strdupFunc: place to save the strdup() function in use
Provides the memory access functions set currently in use
Returns 0 on success
Definition at line 1060 of file xmlmemory.c.
XMLPUBVAR xmlReallocFunc xmlRealloc
XMLPUBVAR xmlFreeFunc xmlFree
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
XMLPUBVAR xmlMallocFunc xmlMalloc
◆ xmlMemMalloc()
xmlMemMalloc: @size: an int specifying the size in byte to allocate.
a malloc() equivalent, with logging of the allocation info.
Returns a pointer to the allocated area or NULL in case of lack of memory.
Definition at line 294 of file xmlmemory.c.
void * xmlMallocLoc(size_t size, const char *file, int line)
Referenced by myMallocFunc(), and xmlInitializeGlobalState().
◆ xmlMemoryDump()
xmlMemoryDump:
Dump in-extenso the memory blocks allocated to the file .memorylist
Definition at line 910 of file xmlmemory.c.
919 xmlMemoryDumpFile =
stderr;
920 else xmlMemoryDumpFile =
dump;
void xmlMemDisplay(FILE *fp)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static unsigned long debugMaxMemSize
static void dump(const void *ptr, unsigned len)
Referenced by main(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemStrdupLoc(), and xmlReallocLoc().
◆ xmlMemoryStrdup()
xmlMemoryStrdup: @str: the initial string pointer
a strdup() equivalent, with logging of the allocation info.
Returns a pointer to the new string or NULL if allocation error occurred.
Definition at line 555 of file xmlmemory.c.
char * xmlMemStrdupLoc(const char *str, const char *file, int line)
Referenced by myStrdupFunc(), and xmlInitializeGlobalState().
◆ xmlMemRealloc()
xmlMemRealloc: @ptr: the initial memory block pointer @size: an int specifying the size in byte to allocate.
a realloc() equivalent, with logging of the allocation info.
Returns a pointer to the allocated area or NULL in case of lack of memory.
Definition at line 403 of file xmlmemory.c.
void * xmlReallocLoc(void *ptr, size_t size, const char *file, int line)
Referenced by myReallocFunc(), and xmlInitializeGlobalState().
◆ xmlMemSetup()
xmlMemSetup: @freeFunc: the free() function to use @mallocFunc: the malloc() function to use @reallocFunc: the realloc() function to use @strdupFunc: the strdup() function to use
Override the default memory access functions with a new set This has to be called before any other libxml routines !
Should this be blocked if there was already some allocations done ?
Returns 0 on success
Definition at line 1022 of file xmlmemory.c.
1028 if (freeFunc ==
NULL)
1030 if (mallocFunc ==
NULL)
1032 if (reallocFunc ==
NULL)
1034 if (strdupFunc ==
NULL)
1043 "xmlMemSetup() Ok\n");
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
XMLPUBVAR xmlReallocFunc xmlRealloc
XMLPUBVAR xmlFreeFunc xmlFree
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
XMLPUBVAR xmlMallocFunc xmlMalloc
XMLPUBVAR void * xmlGenericErrorContext
Referenced by main().
◆ xmlMemShow()
xmlMemShow: @fp: a FILE descriptor used as the output file @nr: number of entries to dump
show a show display of the memory allocated, and dump the @nr last allocated areas which were not freed
Definition at line 865 of file xmlmemory.c.
872 fprintf(fp,
" MEMORY ALLOCATED : %lu, MAX was %lu\n",
877 fprintf(fp,
"NUMBER SIZE TYPE WHERE\n");
879 while ((
p) &&
nr > 0) {
880 fprintf(fp,
"%6lu %6lu ",
p->mh_number,(
unsigned long)
p->mh_size);
881 switch (
p->mh_type) {
887 default:
fprintf(fp,
" ??? in ");
break;
889 if (
p->mh_file !=
NULL)
890 fprintf(fp,
"%s(%u)",
p->mh_file,
p->mh_line);
893 xmlMemContentShow(fp,
p);
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
#define REALLOC_ATOMIC_TYPE
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static unsigned long debugMaxMemSize
#define MALLOC_ATOMIC_TYPE
◆ xmlMemStrdupLoc()
Definition at line 490 of file xmlmemory.c.
501 "xmlMemStrdupLoc : Unsigned overflow\n");
521 debugmem_list_add(
p);
static unsigned int block
static int xmlMemInitialized
ACPI_SIZE strlen(const char *String)
static void * xmlMemTraceBlockAt
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
static unsigned int xmlMemStopAtBlock
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
static unsigned long debugMemBlocks
void xmlMallocBreakpoint(void)
char * strcpy(char *DstString, const char *SrcString)
static unsigned long debugMaxMemSize
XMLPUBVAR void * xmlGenericErrorContext
Referenced by xmlMemoryStrdup().
◆ xmlMemUsed()
xmlMemUsed:
Provides the amount of memory currently allocated
Returns an int representing the amount of memory allocated.
Definition at line 568 of file xmlmemory.c.
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
Referenced by myMallocFunc(), myReallocFunc(), and myStrdupFunc().
◆ xmlReallocLoc()
Definition at line 312 of file xmlmemory.c.
338 oldsize =
p->mh_size;
341 debugmem_list_delete(
p);
347 "xmlReallocLoc : Unsigned overflow\n");
360 "%p : Realloced(%lu -> %lu) Ok\n",
362 (
long unsigned)
size);
376 debugmem_list_add(
p);
384 "Realloced(%d to %d) Ok\n", oldsize,
size);
static int xmlMemInitialized
static void * xmlMemTraceBlockAt
static unsigned long debugMemSize
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
static xmlMutexPtr xmlMemMutex
static size_t double number
static unsigned int xmlMemStopAtBlock
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
static unsigned long debugMemBlocks
void * xmlMallocLoc(size_t size, const char *file, int line)
void xmlMallocBreakpoint(void)
static unsigned long debugMaxMemSize
XMLPUBVAR void * xmlGenericErrorContext
Referenced by xmlMemRealloc().