ReactOS 0.4.16-dev-2206-gc56950d
xmlmemory.c File Reference
#include "libxml.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlerror.h>
#include <libxml/parser.h>
#include <libxml/threads.h>
#include "private/memory.h"
#include "private/threads.h"
Include dependency graph for xmlmemory.c:

Go to the source code of this file.

Classes

struct  memnod
 

Macros

#define IN_LIBXML
 
#define MEMTAG   0x5aa5U
 
#define MALLOC_TYPE   1
 
#define REALLOC_TYPE   2
 
#define STRDUP_TYPE   3
 
#define MALLOC_ATOMIC_TYPE   4
 
#define REALLOC_ATOMIC_TYPE   5
 
#define ALIGN_SIZE   sizeof(double)
 
#define HDR_SIZE   sizeof(MEMHDR)
 
#define RESERVE_SIZE
 
#define MAX_SIZE_T   ((size_t)-1)
 
#define CLIENT_2_HDR(a)   ((void *) (((char *) (a)) - RESERVE_SIZE))
 
#define HDR_2_CLIENT(a)   ((void *) (((char *) (a)) + RESERVE_SIZE))
 
#define Mem_Tag_Err(a)   debugmem_tag_error(a);
 
#define TEST_POINT
 

Typedefs

typedef struct memnod MEMHDR
 

Functions

void xmlMallocBreakpoint (void)
 
static void debugmem_tag_error (void *addr)
 
voidxmlMallocLoc (size_t size, const char *file, int line)
 
voidxmlMallocAtomicLoc (size_t size, const char *file, int line)
 
voidxmlMemMalloc (size_t size)
 
voidxmlReallocLoc (void *ptr, size_t size, const char *file, int line)
 
voidxmlMemRealloc (void *ptr, size_t size)
 
void xmlMemFree (void *ptr)
 
charxmlMemStrdupLoc (const char *str, const char *file, int line)
 
charxmlMemoryStrdup (const char *str)
 
size_t xmlMemSize (void *ptr)
 
int xmlMemUsed (void)
 
int xmlMemBlocks (void)
 
void xmlMemDisplayLast (FILE *fp, long nbBytes)
 
void xmlMemDisplay (FILE *fp)
 
void xmlMemShow (FILE *fp, int nr ATTRIBUTE_UNUSED)
 
void xmlMemoryDump (void)
 
int xmlInitMemory (void)
 
void xmlInitMemoryInternal (void)
 
void xmlCleanupMemory (void)
 
void xmlCleanupMemoryInternal (void)
 
int xmlMemSetup (xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc)
 
int xmlMemGet (xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc)
 
int xmlGcMemSetup (xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocFunc mallocAtomicFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc)
 
int xmlGcMemGet (xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlMallocFunc *mallocAtomicFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc)
 

Variables

static unsigned long debugMemSize = 0
 
static unsigned long debugMemBlocks = 0
 
static unsigned long debugMaxMemSize = 0
 
static xmlMutex xmlMemMutex
 
static unsigned int block =0
 
static unsigned int xmlMemStopAtBlock = 0
 
static voidxmlMemTraceBlockAt = NULL
 

Macro Definition Documentation

◆ ALIGN_SIZE

#define ALIGN_SIZE   sizeof(double)

Definition at line 89 of file xmlmemory.c.

◆ CLIENT_2_HDR

#define CLIENT_2_HDR (   a)    ((void *) (((char *) (a)) - RESERVE_SIZE))

Definition at line 97 of file xmlmemory.c.

◆ HDR_2_CLIENT

#define HDR_2_CLIENT (   a)    ((void *) (((char *) (a)) + RESERVE_SIZE))

Definition at line 98 of file xmlmemory.c.

◆ HDR_SIZE

#define HDR_SIZE   sizeof(MEMHDR)

Definition at line 91 of file xmlmemory.c.

◆ IN_LIBXML

#define IN_LIBXML

Definition at line 7 of file xmlmemory.c.

◆ MALLOC_ATOMIC_TYPE

#define MALLOC_ATOMIC_TYPE   4

Definition at line 69 of file xmlmemory.c.

◆ MALLOC_TYPE

#define MALLOC_TYPE   1

Definition at line 66 of file xmlmemory.c.

◆ MAX_SIZE_T

#define MAX_SIZE_T   ((size_t)-1)

Definition at line 95 of file xmlmemory.c.

◆ Mem_Tag_Err

#define Mem_Tag_Err (   a)    debugmem_tag_error(a);

Definition at line 113 of file xmlmemory.c.

◆ MEMTAG

#define MEMTAG   0x5aa5U

Definition at line 64 of file xmlmemory.c.

◆ REALLOC_ATOMIC_TYPE

#define REALLOC_ATOMIC_TYPE   5

Definition at line 70 of file xmlmemory.c.

◆ REALLOC_TYPE

#define REALLOC_TYPE   2

Definition at line 67 of file xmlmemory.c.

◆ RESERVE_SIZE

#define RESERVE_SIZE
Value:
(((HDR_SIZE + (ALIGN_SIZE-1)) \
#define HDR_SIZE
Definition: xmlmemory.c:91
#define ALIGN_SIZE
Definition: xmlmemory.c:89

Definition at line 92 of file xmlmemory.c.

◆ STRDUP_TYPE

#define STRDUP_TYPE   3

Definition at line 68 of file xmlmemory.c.

◆ TEST_POINT

#define TEST_POINT

Definition at line 116 of file xmlmemory.c.

Typedef Documentation

◆ MEMHDR

typedef struct memnod MEMHDR

Function Documentation

◆ debugmem_tag_error()

static void debugmem_tag_error ( void addr)
static

Definition at line 734 of file xmlmemory.c.

735{
737 "Memory tag error occurs :%p \n\t bye\n", p);
738#ifdef MEM_LIST
739 if (stderr)
741#endif
742}
#define stderr
GLfloat GLfloat p
Definition: glext.h:8902
void * xmlGenericErrorContext
Definition: globals.c:410
xmlGenericErrorFunc xmlGenericError
Definition: globals.c:396
void xmlMemDisplay(FILE *fp)
Definition: xmlmemory.c:644

◆ xmlCleanupMemory()

void xmlCleanupMemory ( void  )

xmlCleanupMemory:

DEPRECATED: This function is a no-op. 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.

Definition at line 870 of file xmlmemory.c.

870 {
871}

◆ xmlCleanupMemoryInternal()

void xmlCleanupMemoryInternal ( void  )

xmlCleanupMemoryInternal:

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 880 of file xmlmemory.c.

880 {
881 /*
882 * Don't clean up mutex on Windows. Global state destructors can call
883 * malloc functions after xmlCleanupParser was called. If memory
884 * debugging is enabled, xmlMemMutex can be used after cleanup.
885 *
886 * See python/tests/thread2.py
887 */
888#if !defined(LIBXML_THREAD_ENABLED) || !defined(_WIN32)
890#endif
891}
XML_HIDDEN void xmlCleanupMutex(xmlMutexPtr mutex)
Definition: threads.c:166
static xmlMutex xmlMemMutex
Definition: xmlmemory.c:38

Referenced by xmlCleanupParser().

◆ xmlGcMemGet()

int xmlGcMemGet ( xmlFreeFunc freeFunc,
xmlMallocFunc *  mallocFunc,
xmlMallocFunc *  mallocAtomicFunc,
xmlReallocFunc reallocFunc,
xmlStrdupFunc strdupFunc 
)

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 1003 of file xmlmemory.c.

1005 {
1006 if (freeFunc != NULL) *freeFunc = xmlFree;
1007 if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
1008 if (mallocAtomicFunc != NULL) *mallocAtomicFunc = xmlMallocAtomic;
1009 if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
1010 if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
1011 return(0);
1012}
#define NULL
Definition: types.h:112
xmlReallocFunc xmlRealloc
Definition: globals.c:214
xmlFreeFunc xmlFree
Definition: globals.c:184
xmlMallocFunc xmlMalloc
Definition: globals.c:193
xmlMallocFunc xmlMallocAtomic
Definition: globals.c:204
xmlStrdupFunc xmlMemStrdup
Definition: globals.c:235

◆ xmlGcMemSetup()

int xmlGcMemSetup ( xmlFreeFunc  freeFunc,
xmlMallocFunc  mallocFunc,
xmlMallocFunc  mallocAtomicFunc,
xmlReallocFunc  reallocFunc,
xmlStrdupFunc  strdupFunc 
)

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 967 of file xmlmemory.c.

969 {
970 if (freeFunc == NULL)
971 return(-1);
972 if (mallocFunc == NULL)
973 return(-1);
974 if (mallocAtomicFunc == NULL)
975 return(-1);
976 if (reallocFunc == NULL)
977 return(-1);
978 if (strdupFunc == NULL)
979 return(-1);
980 xmlFree = freeFunc;
981 xmlMalloc = mallocFunc;
982 xmlMallocAtomic = mallocAtomicFunc;
983 xmlRealloc = reallocFunc;
984 xmlMemStrdup = strdupFunc;
985 return(0);
986}

◆ xmlInitMemory()

int xmlInitMemory ( void  )

xmlInitMemory:

DEPRECATED: Alias for xmlInitParser.

Definition at line 833 of file xmlmemory.c.

833 {
835 return(0);
836}
XML_GLOBALS_PARSER XMLPUBFUN void xmlInitParser(void)
Definition: threads.c:569

◆ xmlInitMemoryInternal()

void xmlInitMemoryInternal ( void  )

xmlInitMemoryInternal:

Initialize the memory layer.

Returns 0 on success

Definition at line 846 of file xmlmemory.c.

846 {
847 char *breakpoint;
849
850 breakpoint = getenv("XML_MEM_BREAKPOINT");
851 if (breakpoint != NULL) {
853 }
854 breakpoint = getenv("XML_MEM_TRACE");
855 if (breakpoint != NULL) {
857 }
858
859}
char *CDECL getenv(const char *name)
Definition: environ.c:227
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl sscanf(const char *, const char *,...) __WINE_CRT_SCANF_ATTR(2
void breakpoint(void)
XML_HIDDEN void xmlInitMutex(xmlMutexPtr mutex)
Definition: threads.c:128
static unsigned int xmlMemStopAtBlock
Definition: xmlmemory.c:102
static void * xmlMemTraceBlockAt
Definition: xmlmemory.c:103

Referenced by xmlInitParser().

◆ xmlMallocAtomicLoc()

void * xmlMallocAtomicLoc ( size_t  size,
const char file,
int  line 
)

Definition at line 210 of file xmlmemory.c.

211{
212 MEMHDR *p;
213 void *ret;
214
216
218
219 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
221 "xmlMallocAtomicLoc : Unsigned overflow\n");
222 return(NULL);
223 }
224
226
227 if (!p) {
229 "xmlMallocAtomicLoc : Out of free space\n");
230 return(NULL);
231 }
232 p->mh_tag = MEMTAG;
233 p->mh_size = size;
234 p->mh_type = MALLOC_ATOMIC_TYPE;
235 p->mh_file = file;
236 p->mh_line = line;
238 p->mh_number = ++block;
242#ifdef MEM_LIST
243 debugmem_list_add(p);
244#endif
246
247 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
248
249 ret = HDR_2_CLIENT(p);
250
251 if (xmlMemTraceBlockAt == ret) {
253 "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
254 (long unsigned)size);
256 }
257
259
260 return(ret);
261}
#define malloc
Definition: debug_ros.c:4
return ret
Definition: mutex.c:146
GLsizeiptr size
Definition: glext.h:5919
XMLPUBFUN void xmlMutexLock(xmlMutexPtr tok)
Definition: threads.c:201
XMLPUBFUN void xmlMutexUnlock(xmlMutexPtr tok)
Definition: threads.c:225
Definition: fci.c:127
Definition: parser.c:49
void xmlMallocBreakpoint(void)
Definition: xmlmemory.c:128
#define MALLOC_ATOMIC_TYPE
Definition: xmlmemory.c:69
static unsigned int block
Definition: xmlmemory.c:101
#define HDR_2_CLIENT(a)
Definition: xmlmemory.c:98
#define MEMTAG
Definition: xmlmemory.c:64
#define TEST_POINT
Definition: xmlmemory.c:116
static unsigned long debugMemBlocks
Definition: xmlmemory.c:36
#define RESERVE_SIZE
Definition: xmlmemory.c:92
static unsigned long debugMemSize
Definition: xmlmemory.c:35
#define MAX_SIZE_T
Definition: xmlmemory.c:95
static unsigned long debugMaxMemSize
Definition: xmlmemory.c:37

◆ xmlMallocBreakpoint()

void xmlMallocBreakpoint ( void  )

xmlMallocBreakpoint:

Breakpoint to use in conjunction with xmlMemStopAtBlock. When the block number reaches the specified value this function is called. One need to add a breakpoint to it to get the context in which the given block is allocated.

Definition at line 128 of file xmlmemory.c.

128 {
130 "xmlMallocBreakpoint reached on block %d\n", xmlMemStopAtBlock);
131}

Referenced by xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemFree(), xmlMemStrdupLoc(), and xmlReallocLoc().

◆ xmlMallocLoc()

void * xmlMallocLoc ( size_t  size,
const char file,
int  line 
)

Definition at line 145 of file xmlmemory.c.

146{
147 MEMHDR *p;
148 void *ret;
149
151
153
154 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
156 "xmlMallocLoc : Unsigned overflow\n");
157 return(NULL);
158 }
159
161
162 if (!p) {
164 "xmlMallocLoc : Out of free space\n");
165 return(NULL);
166 }
167 p->mh_tag = MEMTAG;
168 p->mh_size = size;
169 p->mh_type = MALLOC_TYPE;
170 p->mh_file = file;
171 p->mh_line = line;
173 p->mh_number = ++block;
177#ifdef MEM_LIST
178 debugmem_list_add(p);
179#endif
181
182 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
183
184 ret = HDR_2_CLIENT(p);
185
186 if (xmlMemTraceBlockAt == ret) {
188 "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
189 (long unsigned)size);
191 }
192
194
195 return(ret);
196}
#define MALLOC_TYPE
Definition: xmlmemory.c:66

Referenced by xmlMemMalloc(), and xmlReallocLoc().

◆ xmlMemBlocks()

int xmlMemBlocks ( void  )

xmlMemBlocks:

Provides the number of memory areas currently allocated

Returns an int representing the number of blocks

Definition at line 557 of file xmlmemory.c.

557 {
558 int res;
559
563 return(res);
564}
GLuint res
Definition: glext.h:9613

◆ xmlMemDisplay()

void xmlMemDisplay ( FILE fp)

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 644 of file xmlmemory.c.

645{
646#ifdef MEM_LIST
647 MEMHDR *p;
648 unsigned idx;
649 int nb = 0;
650 time_t currentTime;
651 char buf[500];
652 struct tm * tstruct;
653#endif
654 FILE *old_fp = fp;
655
656 if (fp == NULL) {
657 fp = fopen(".memorylist", "w");
658 if (fp == NULL)
659 return;
660 }
661
662#ifdef MEM_LIST
663 currentTime = time(NULL);
664 tstruct = localtime(&currentTime);
665 strftime(buf, sizeof(buf) - 1, "%I:%M:%S %p", tstruct);
666 fprintf(fp," %s\n\n", buf);
667
668
669 fprintf(fp," MEMORY ALLOCATED : %lu, MAX was %lu\n",
671 fprintf(fp,"BLOCK NUMBER SIZE TYPE\n");
672 idx = 0;
674 p = memlist;
675 while (p) {
676 fprintf(fp,"%-5u %6lu %6lu ",idx++,p->mh_number,
677 (unsigned long)p->mh_size);
678 switch (p->mh_type) {
679 case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
680 case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
681 case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
682 case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
683 case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
684 default:
685 fprintf(fp,"Unknown memory block, may be corrupted");
687 if (old_fp == NULL)
688 fclose(fp);
689 return;
690 }
691 if (p->mh_file != NULL) fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
692 if (p->mh_tag != MEMTAG)
693 fprintf(fp," INVALID");
694 nb++;
695
696 fprintf(fp,"\n");
697 p = p->mh_next;
698 }
700#else
701 fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
702#endif
703 if (old_fp == NULL)
704 fclose(fp);
705}
unsigned int idx
Definition: utils.c:41
int CDECL fclose(FILE *file)
Definition: file.c:3757
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
__time32_t time_t
Definition: corecrt.h:228
_ACRTIMP size_t __cdecl strftime(char *, size_t, const char *, const struct tm *)
Definition: time.c:1537
static struct tm * localtime(const time_t *t)
Definition: time.h:121
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
__u16 time
Definition: mkdosfs.c:8
#define REALLOC_ATOMIC_TYPE
Definition: xmlmemory.c:70
#define STRDUP_TYPE
Definition: xmlmemory.c:68
#define REALLOC_TYPE
Definition: xmlmemory.c:67

Referenced by debugmem_tag_error(), and xmlMemoryDump().

◆ xmlMemDisplayLast()

void xmlMemDisplayLast ( FILE fp,
long  nbBytes 
)

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 577 of file xmlmemory.c.

578{
579#ifdef MEM_LIST
580 MEMHDR *p;
581 unsigned idx;
582 int nb = 0;
583#endif
584 FILE *old_fp = fp;
585
586 if (nbBytes <= 0)
587 return;
588
589 if (fp == NULL) {
590 fp = fopen(".memorylist", "w");
591 if (fp == NULL)
592 return;
593 }
594
595#ifdef MEM_LIST
596 fprintf(fp," Last %li MEMORY ALLOCATED : %lu, MAX was %lu\n",
597 nbBytes, debugMemSize, debugMaxMemSize);
598 fprintf(fp,"BLOCK NUMBER SIZE TYPE\n");
599 idx = 0;
601 p = memlist;
602 while ((p) && (nbBytes > 0)) {
603 fprintf(fp,"%-5u %6lu %6lu ",idx++,p->mh_number,
604 (unsigned long)p->mh_size);
605 switch (p->mh_type) {
606 case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
607 case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
608 case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
609 case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
610 case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
611 default:
612 fprintf(fp,"Unknown memory block, may be corrupted");
614 if (old_fp == NULL)
615 fclose(fp);
616 return;
617 }
618 if (p->mh_file != NULL) fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
619 if (p->mh_tag != MEMTAG)
620 fprintf(fp," INVALID");
621 nb++;
622
623 fprintf(fp,"\n");
624 nbBytes -= (unsigned long)p->mh_size;
625 p = p->mh_next;
626 }
628#else
629 fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
630#endif
631 if (old_fp == NULL)
632 fclose(fp);
633}
#define long
Definition: qsort.c:33

◆ xmlMemFree()

void xmlMemFree ( void ptr)

xmlMemFree: @ptr: the memory block pointer

a free() equivalent, with error checking.

Definition at line 381 of file xmlmemory.c.

382{
383 MEMHDR *p;
384 char *target;
385
386 if (ptr == NULL)
387 return;
388
389 if (ptr == (void *) -1) {
391 "trying to free pointer from freed area\n");
392 goto error;
393 }
394
395 if (xmlMemTraceBlockAt == ptr) {
397 "%p : Freed()\n", xmlMemTraceBlockAt);
399 }
400
402
403 target = (char *) ptr;
404
405 p = CLIENT_2_HDR(ptr);
406 if (p->mh_tag != MEMTAG) {
407 Mem_Tag_Err(p);
408 goto error;
409 }
410 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
411 p->mh_tag = ~MEMTAG;
412 memset(target, -1, p->mh_size);
414 debugMemSize -= p->mh_size;
416#ifdef MEM_LIST
417 debugmem_list_delete(p);
418#endif
420
421 free(p);
422
424
425 return;
426
427error:
429 "xmlMemFree(%p) error\n", ptr);
431 return;
432}
#define free
Definition: debug_ros.c:5
#define error(str)
Definition: mkdosfs.c:1605
static PVOID ptr
Definition: dispmode.c:27
#define memset(x, y, z)
Definition: compat.h:39
Definition: tools.h:99
#define Mem_Tag_Err(a)
Definition: xmlmemory.c:113
#define CLIENT_2_HDR(a)
Definition: xmlmemory.c:97

◆ xmlMemGet()

int xmlMemGet ( xmlFreeFunc freeFunc,
xmlMallocFunc *  mallocFunc,
xmlReallocFunc reallocFunc,
xmlStrdupFunc strdupFunc 
)

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 939 of file xmlmemory.c.

940 {
941 if (freeFunc != NULL) *freeFunc = xmlFree;
942 if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
943 if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
944 if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
945 return(0);
946}

◆ xmlMemMalloc()

void * xmlMemMalloc ( size_t  size)

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 272 of file xmlmemory.c.

273{
274 return(xmlMallocLoc(size, "none", 0));
275}
void * xmlMallocLoc(size_t size, const char *file, int line)
Definition: xmlmemory.c:145

◆ xmlMemoryDump()

void xmlMemoryDump ( void  )

xmlMemoryDump:

Dump in-extenso the memory blocks allocated to the file .memorylist

Definition at line 802 of file xmlmemory.c.

803{
804#ifdef MEM_LIST
805 FILE *dump;
806
807 if (debugMaxMemSize == 0)
808 return;
809 dump = fopen(".memdump", "w");
810 if (dump == NULL)
811 xmlMemoryDumpFile = stderr;
812 else xmlMemoryDumpFile = dump;
813
814 xmlMemDisplay(xmlMemoryDumpFile);
815
816 if (dump != NULL) fclose(dump);
817#endif /* MEM_LIST */
818}
static void dump(const void *ptr, unsigned len)
Definition: msc.c:95

◆ xmlMemoryStrdup()

char * xmlMemoryStrdup ( const char str)

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 510 of file xmlmemory.c.

510 {
511 return(xmlMemStrdupLoc(str, "none", 0));
512}
const WCHAR * str
char * xmlMemStrdupLoc(const char *str, const char *file, int line)
Definition: xmlmemory.c:446

◆ xmlMemRealloc()

void * xmlMemRealloc ( void ptr,
size_t  size 
)

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 370 of file xmlmemory.c.

370 {
371 return(xmlReallocLoc(ptr, size, "none", 0));
372}
void * xmlReallocLoc(void *ptr, size_t size, const char *file, int line)
Definition: xmlmemory.c:290

◆ xmlMemSetup()

int xmlMemSetup ( xmlFreeFunc  freeFunc,
xmlMallocFunc  mallocFunc,
xmlReallocFunc  reallocFunc,
xmlStrdupFunc  strdupFunc 
)

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 909 of file xmlmemory.c.

910 {
911 if (freeFunc == NULL)
912 return(-1);
913 if (mallocFunc == NULL)
914 return(-1);
915 if (reallocFunc == NULL)
916 return(-1);
917 if (strdupFunc == NULL)
918 return(-1);
919 xmlFree = freeFunc;
920 xmlMalloc = mallocFunc;
921 xmlMallocAtomic = mallocFunc;
922 xmlRealloc = reallocFunc;
923 xmlMemStrdup = strdupFunc;
924 return(0);
925}

◆ xmlMemShow()

void xmlMemShow ( FILE fp,
int nr  ATTRIBUTE_UNUSED 
)

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 758 of file xmlmemory.c.

759{
760#ifdef MEM_LIST
761 MEMHDR *p;
762#endif
763
764 if (fp != NULL)
765 fprintf(fp," MEMORY ALLOCATED : %lu, MAX was %lu\n",
767#ifdef MEM_LIST
769 if (nr > 0) {
770 fprintf(fp,"NUMBER SIZE TYPE WHERE\n");
771 p = memlist;
772 while ((p) && nr > 0) {
773 fprintf(fp,"%6lu %6lu ",p->mh_number,(unsigned long)p->mh_size);
774 switch (p->mh_type) {
775 case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
776 case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
777 case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
778 case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
779 case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
780 default:fprintf(fp," ??? in ");break;
781 }
782 if (p->mh_file != NULL)
783 fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
784 if (p->mh_tag != MEMTAG)
785 fprintf(fp," INVALID");
786 fprintf(fp,"\n");
787 nr--;
788 p = p->mh_next;
789 }
790 }
792#endif /* MEM_LIST */
793}
ULONG nr
Definition: thread.c:7

◆ xmlMemSize()

size_t xmlMemSize ( void ptr)

xmlMemSize: @ptr: pointer to the memory allocation

Returns the size of a memory allocation.

Definition at line 522 of file xmlmemory.c.

522 {
523 MEMHDR *p;
524
525 if (ptr == NULL)
526 return(0);
527
528 p = CLIENT_2_HDR(ptr);
529 if (p->mh_tag != MEMTAG)
530 return(0);
531
532 return(p->mh_size);
533}

◆ xmlMemStrdupLoc()

char * xmlMemStrdupLoc ( const char str,
const char file,
int  line 
)

Definition at line 446 of file xmlmemory.c.

447{
448 char *s;
449 size_t size = strlen(str) + 1;
450 MEMHDR *p;
451
454
455 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
457 "xmlMemStrdupLoc : Unsigned overflow\n");
458 return(NULL);
459 }
460
462 if (!p) {
463 goto error;
464 }
465 p->mh_tag = MEMTAG;
466 p->mh_size = size;
467 p->mh_type = STRDUP_TYPE;
468 p->mh_file = file;
469 p->mh_line = line;
471 p->mh_number = ++block;
475#ifdef MEM_LIST
476 debugmem_list_add(p);
477#endif
479
480 s = (char *) HDR_2_CLIENT(p);
481
482 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
483
484 strcpy(s,str);
485
487
488 if (xmlMemTraceBlockAt == s) {
490 "%p : Strdup() Ok\n", xmlMemTraceBlockAt);
492 }
493
494 return(s);
495
496error:
497 return(NULL);
498}
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
GLdouble s
Definition: gl.h:2039
strcpy
Definition: string.h:131

Referenced by xmlMemoryStrdup().

◆ xmlMemUsed()

int xmlMemUsed ( void  )

xmlMemUsed:

Provides the amount of memory currently allocated

Returns an int representing the amount of memory allocated.

Definition at line 544 of file xmlmemory.c.

544 {
545 return(debugMemSize);
546}

◆ xmlReallocLoc()

void * xmlReallocLoc ( void ptr,
size_t  size,
const char file,
int  line 
)

Definition at line 290 of file xmlmemory.c.

291{
292 MEMHDR *p, *tmp;
293 unsigned long number;
294
295 if (ptr == NULL)
296 return(xmlMallocLoc(size, file, line));
297
300
301 p = CLIENT_2_HDR(ptr);
302 number = p->mh_number;
304 if (p->mh_tag != MEMTAG) {
305 Mem_Tag_Err(p);
306 goto error;
307 }
308 p->mh_tag = ~MEMTAG;
310 debugMemSize -= p->mh_size;
312#ifdef MEM_LIST
313 debugmem_list_delete(p);
314#endif
316
317 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
319 "xmlReallocLoc : Unsigned overflow\n");
320 return(NULL);
321 }
322
323 tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
324 if (!tmp) {
325 free(p);
326 goto error;
327 }
328 p = tmp;
329 if (xmlMemTraceBlockAt == ptr) {
331 "%p : Realloced(%lu -> %lu) Ok\n",
332 xmlMemTraceBlockAt, (long unsigned)p->mh_size,
333 (long unsigned)size);
335 }
336 p->mh_tag = MEMTAG;
337 p->mh_number = number;
338 p->mh_type = REALLOC_TYPE;
339 p->mh_size = size;
340 p->mh_file = file;
341 p->mh_line = line;
346#ifdef MEM_LIST
347 debugmem_list_add(p);
348#endif
350
352
353 return(HDR_2_CLIENT(p));
354
355error:
356 return(NULL);
357}
#define realloc
Definition: debug_ros.c:6
static unsigned int number
Definition: dsound.c:1479

Referenced by xmlMemRealloc().

Variable Documentation

◆ block

unsigned int block =0
static

Definition at line 101 of file xmlmemory.c.

Referenced by __declspec(), __find_get_block(), __getblk(), _aligned_free_base(), _aligned_msize_base(), _aligned_offset_realloc_base(), _aligned_offset_recalloc_base(), _aligned_realloc_base(), _aligned_recalloc_base(), _chm_decompress_block(), _chm_get_cmpblock_bounds(), absynth_1to1_i486(), add_block(), add_data_block(), add_data_to_folder(), add_typeinfo_block(), adns__transfer_interim(), tinyxml2::MemPoolT< SIZE >::Alloc(), alloc_pioinfo_block(), append_data(), AVIFILE_SamplesToBlock(), Base64ToBinary(), begin_block_execution(), blake2b_compress(), block_size(), BlockChainStream_GetBlockAtOffset(), chksum_crc32(), codeview_snarf(), copy_data_blocks(), create_gpe_block(), create_io_inherit_block(), create_library_block(), ctl2_alloc_segment(), d3dx_effect_ApplyParameterBlock(), d3dx_effect_cleanup(), decode_block(), decode_mcu(), decode_mcu_AC_first(), decode_mcu_AC_refine(), decode_mcu_DC_first(), decode_mcu_sub(), desfunc(), detect_gpes(), do_find_gpe(), do_for_all_gpes(), do_initialize_gpe_block(), dwarf2_parse_inlined_subroutine(), dwarf2_parse_subprogram_block(), dwarf2_parse_variable(), encode_mcu(), encode_mcu_AC_first(), encode_mcu_AC_refine(), encode_one_block(), Slicer::evalRBArray(), ext2_alloc_block(), ext2_block_map(), ext2_mkdir(), ext2_new_dir_block(), ext2_read_block(), ext2_test_block_bitmap(), ext2_test_block_bitmap_range(), ext2_write_block(), Ext2AddDotEntries(), Ext2LoadBuffer(), Ext2SaveBuffer(), Ext2ZeroBuffer(), ext3_add_entry(), ext3_append(), ext3_bread(), ext3_find_entry(), ext4_block_in_group(), ext4_ext_binsearch(), ext4_ext_binsearch_idx(), ext4_ext_find_goal(), ext4_ext_pblock(), ext4_ext_rm_leaf(), ext4_ext_search_right(), ext4_find_extent(), ext4_free_blocks(), ext4_idx_pblock(), ext4_new_meta_blocks(), ext_to_block(), extents_bread(), extents_bwrite(), FCIDestroy(), FDSA_InsertItem(), find_last_block(), for(), for_each_gpe_block(), frame_reset_post_end_block(), frame_setup_base_scope(), free_data_block(), free_folder(), free_parameter_block(), ft_free(), ft_mem_alloc(), ft_mem_qalloc(), ft_mem_qrealloc(), ft_mem_realloc(), ft_realloc(), fwpolicy2_get_BlockAllInboundTraffic(), fwpolicy2_put_BlockAllInboundTraffic(), get_block_bh(), get_block_bh_mdl(), get_block_bh_pin(), get_cache_glyph(), get_cache_glyph_widths(), get_file_version(), get_valid_parameter_block(), gl_destroy_list(), gpe_block_apply_action(), gpe_block_mask_safe(), gpe_from_block(), hash(), htest_one_block(), IAVIStream_fnRead(), idx_to_block(), if(), III_hybrid(), ImmDestroyIMCC(), ldap_memfreeA(), ldap_memfreeW(), map_bh(), maybe_end_block(), msvcrt_create_io_inherit_block(), ntom_ins2outs(), OleUnblockServer(), ParseSharedPacket(), peek_next_op(), pending_flush(), PerfDeleteInstance(), record_parameter(), sb_bread(), sb_find_get_block(), sb_getblk(), sb_getblk_zero(), select_heap(), set_cache_glyph(), set_cache_glyph_widths(), sha1_transform(), stabs_parse(), StartBalanceW(), surface_cpu_blt_compressed(), swap_endian(), symt_add_func_local(), symt_close_func_block(), symt_enum_locals_helper(), symt_open_func_block(), test_effect_parameter_block(), test_FDICopy(), test_fdsa(), trace_method_abort(), uacpi_deinitialize_events(), UDFProcessSequence(), UDFReadVDS(), UDFUpdateVDS(), UDFVerifySequence(), uninstall_gpe_block(), update_scope(), urlcache_entry_alloc(), urlcache_entry_free(), WerRegisterMemoryBlock(), WerUnregisterMemoryBlock(), write_data_blocks(), xmlMallocAtomicLoc(), xmlMallocLoc(), and xmlMemStrdupLoc().

◆ debugMaxMemSize

◆ debugMemBlocks

unsigned long debugMemBlocks = 0
static

◆ debugMemSize

unsigned long debugMemSize = 0
static

MEM_LIST:

keep track of all allocated blocks for error reporting Always build the memory list !

Definition at line 35 of file xmlmemory.c.

Referenced by xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemFree(), xmlMemShow(), xmlMemStrdupLoc(), xmlMemUsed(), and xmlReallocLoc().

◆ xmlMemMutex

◆ xmlMemStopAtBlock

◆ xmlMemTraceBlockAt

void* xmlMemTraceBlockAt = NULL
static