ReactOS 0.4.16-dev-2208-g6350669
xmlmemory.h File Reference
#include <stdio.h>
#include <libxml/xmlversion.h>
Include dependency graph for xmlmemory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XML_GLOBALS_ALLOC
 

Typedefs

typedef void(* xmlFreeFunc) (void *mem)
 
typedef voidLIBXML_ATTR_ALLOC_SIZE(1) *xmlMallocFunc) (size_t size)
 
typedef void *(* xmlReallocFunc) (void *mem, size_t size)
 
typedef char *(* xmlStrdupFunc) (const char *str)
 

Functions

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

Variables

XMLPUBVAR xmlMallocFunc xmlMalloc
 
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
 
XMLPUBVAR xmlReallocFunc xmlRealloc
 
XMLPUBVAR xmlFreeFunc xmlFree
 
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
 

Macro Definition Documentation

◆ XML_GLOBALS_ALLOC

#define XML_GLOBALS_ALLOC

DOC_DISABLE

Definition at line 91 of file xmlmemory.h.

Typedef Documentation

◆ LIBXML_ATTR_ALLOC_SIZE

typedef void * LIBXML_ATTR_ALLOC_SIZE(1) *xmlMallocFunc)(size_t 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 40 of file xmlmemory.h.

◆ xmlFreeFunc

typedef void(* xmlFreeFunc) (void *mem)

xmlFreeFunc: @mem: an already allocated block of memory

Signature for a free() implementation.

Definition at line 31 of file xmlmemory.h.

◆ xmlReallocFunc

typedef void *(* xmlReallocFunc) (void *mem, size_t size)

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 51 of file xmlmemory.h.

◆ xmlStrdupFunc

typedef char *(* xmlStrdupFunc) (const char *str)

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 61 of file xmlmemory.h.

Function Documentation

◆ xmlCleanupMemory()

XML_DEPRECATED XMLPUBFUN 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}

◆ xmlGcMemGet()

XMLPUBFUN 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()

XMLPUBFUN 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()

XML_DEPRECATED XMLPUBFUN 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

◆ xmlMallocAtomicLoc()

XMLPUBFUN 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
GLfloat GLfloat p
Definition: glext.h:8902
XMLPUBFUN void xmlMutexLock(xmlMutexPtr tok)
Definition: threads.c:201
XMLPUBFUN void xmlMutexUnlock(xmlMutexPtr tok)
Definition: threads.c:225
void * xmlGenericErrorContext
Definition: globals.c:410
xmlGenericErrorFunc xmlGenericError
Definition: globals.c:396
Definition: fci.c:127
Definition: parser.c:49
void xmlMallocBreakpoint(void)
Definition: xmlmemory.c:128
#define MALLOC_ATOMIC_TYPE
Definition: xmlmemory.c:69
static xmlMutex xmlMemMutex
Definition: xmlmemory.c:38
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
static unsigned int xmlMemStopAtBlock
Definition: xmlmemory.c:102
#define RESERVE_SIZE
Definition: xmlmemory.c:92
static unsigned long debugMemSize
Definition: xmlmemory.c:35
static void * xmlMemTraceBlockAt
Definition: xmlmemory.c:103
#define MAX_SIZE_T
Definition: xmlmemory.c:95
static unsigned long debugMaxMemSize
Definition: xmlmemory.c:37

◆ xmlMallocLoc()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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}
#define stderr
static void dump(const void *ptr, unsigned len)
Definition: msc.c:95
void xmlMemDisplay(FILE *fp)
Definition: xmlmemory.c:644

◆ xmlMemoryStrdup()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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()

XMLPUBFUN 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

◆ xmlFree

Definition at line 96 of file xmlmemory.h.

◆ xmlMalloc

XMLPUBVAR xmlMallocFunc xmlMalloc

DOC_ENABLE

Definition at line 93 of file xmlmemory.h.

◆ xmlMallocAtomic

XMLPUBVAR xmlMallocFunc xmlMallocAtomic

Definition at line 94 of file xmlmemory.h.

◆ xmlMemStrdup

XMLPUBVAR xmlStrdupFunc xmlMemStrdup

Definition at line 97 of file xmlmemory.h.

◆ xmlRealloc

Definition at line 95 of file xmlmemory.h.