ReactOS 0.4.15-dev-7928-g68a8619
xmlmemory.c File Reference
#include "libxml.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <libxml/globals.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlerror.h>
#include <libxml/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)
 
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 xmlCleanupMemory (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 int xmlMemInitialized = 0
 
static unsigned long debugMemSize = 0
 
static unsigned long debugMemBlocks = 0
 
static unsigned long debugMaxMemSize = 0
 
static xmlMutexPtr xmlMemMutex = NULL
 
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 841 of file xmlmemory.c.

842{
844 "Memory tag error occurs :%p \n\t bye\n", p);
845#ifdef MEM_LIST
846 if (stderr)
848#endif
849}
GLfloat GLfloat p
Definition: glext.h:8902
#define stderr
Definition: stdio.h:100
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
void xmlMemDisplay(FILE *fp)
Definition: xmlmemory.c:739

◆ xmlCleanupMemory()

void xmlCleanupMemory ( void  )

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.

989 {
990#ifdef DEBUG_MEMORY
992 "xmlCleanupMemory()\n");
993#endif
994 if (xmlMemInitialized == 0)
995 return;
996
1000#ifdef DEBUG_MEMORY
1002 "xmlCleanupMemory() Ok\n");
1003#endif
1004}
#define NULL
Definition: types.h:112
XMLPUBFUN void XMLCALL xmlFreeMutex(xmlMutexPtr tok)
Definition: threads.c:197
static int xmlMemInitialized
Definition: xmlmemory.c:34
static xmlMutexPtr 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 1132 of file xmlmemory.c.

1134 {
1135 if (freeFunc != NULL) *freeFunc = xmlFree;
1136 if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
1137 if (mallocAtomicFunc != NULL) *mallocAtomicFunc = xmlMallocAtomic;
1138 if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
1139 if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
1140 return(0);
1141}
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:249
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
Definition: globals.h:252
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:248
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:250

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

1090 {
1091#ifdef DEBUG_MEMORY
1093 "xmlGcMemSetup()\n");
1094#endif
1095 if (freeFunc == NULL)
1096 return(-1);
1097 if (mallocFunc == NULL)
1098 return(-1);
1099 if (mallocAtomicFunc == NULL)
1100 return(-1);
1101 if (reallocFunc == NULL)
1102 return(-1);
1103 if (strdupFunc == NULL)
1104 return(-1);
1105 xmlFree = freeFunc;
1106 xmlMalloc = mallocFunc;
1107 xmlMallocAtomic = mallocAtomicFunc;
1108 xmlRealloc = reallocFunc;
1109 xmlMemStrdup = strdupFunc;
1110#ifdef DEBUG_MEMORY
1112 "xmlGcMemSetup() Ok\n");
1113#endif
1114 return(0);
1115}

◆ xmlInitMemory()

int xmlInitMemory ( void  )

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.

947{
948 char *breakpoint;
949#ifdef DEBUG_MEMORY
951 "xmlInitMemory()\n");
952#endif
953 /*
954 This is really not good code (see Bug 130419). Suggestions for
955 improvement will be welcome!
956 */
957 if (xmlMemInitialized) return(-1);
960
961 breakpoint = getenv("XML_MEM_BREAKPOINT");
962 if (breakpoint != NULL) {
964 }
965 breakpoint = getenv("XML_MEM_TRACE");
966 if (breakpoint != NULL) {
968 }
969
970#ifdef DEBUG_MEMORY
972 "xmlInitMemory() Ok\n");
973#endif
974 return(0);
975}
void breakpoint(void)
_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)
Definition: threads.c:168
static unsigned int xmlMemStopAtBlock
Definition: xmlmemory.c:102
static void * xmlMemTraceBlockAt
Definition: xmlmemory.c:103

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

◆ xmlMallocAtomicLoc()

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

Definition at line 221 of file xmlmemory.c.

222{
223 MEMHDR *p;
224 void *ret;
225
227#ifdef DEBUG_MEMORY
229 "Malloc(%d)\n",size);
230#endif
231
233
234 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
236 "xmlMallocAtomicLoc : Unsigned overflow\n");
238 return(NULL);
239 }
240
242
243 if (!p) {
245 "xmlMallocAtomicLoc : Out of free space\n");
247 return(NULL);
248 }
249 p->mh_tag = MEMTAG;
250 p->mh_size = size;
251 p->mh_type = MALLOC_ATOMIC_TYPE;
252 p->mh_file = file;
253 p->mh_line = line;
255 p->mh_number = ++block;
259#ifdef MEM_LIST
260 debugmem_list_add(p);
261#endif
263
264#ifdef DEBUG_MEMORY
266 "Malloc(%d) Ok\n",size);
267#endif
268
269 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
270
271 ret = HDR_2_CLIENT(p);
272
273 if (xmlMemTraceBlockAt == ret) {
275 "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
276 (long unsigned)size);
278 }
279
281
282 return(ret);
283}
#define malloc
Definition: debug_ros.c:4
GLsizeiptr size
Definition: glext.h:5919
Definition: fci.c:127
Definition: parser.c:49
XMLPUBFUN void XMLCALL xmlMutexUnlock(xmlMutexPtr tok)
Definition: threads.c:248
XMLPUBFUN void XMLCALL xmlMutexLock(xmlMutexPtr tok)
Definition: threads.c:220
int ret
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
int xmlInitMemory(void)
Definition: xmlmemory.c:946
static unsigned long debugMaxMemSize
Definition: xmlmemory.c:37
void xmlMemoryDump(void)
Definition: xmlmemory.c:910

◆ 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#ifdef DEBUG_MEMORY
153 "Malloc(%d)\n",size);
154#endif
155
157
158 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
160 "xmlMallocLoc : Unsigned overflow\n");
162 return(NULL);
163 }
164
166
167 if (!p) {
169 "xmlMallocLoc : Out of free space\n");
171 return(NULL);
172 }
173 p->mh_tag = MEMTAG;
174 p->mh_size = size;
175 p->mh_type = MALLOC_TYPE;
176 p->mh_file = file;
177 p->mh_line = line;
179 p->mh_number = ++block;
183#ifdef MEM_LIST
184 debugmem_list_add(p);
185#endif
187
188#ifdef DEBUG_MEMORY
190 "Malloc(%d) Ok\n",size);
191#endif
192
193 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
194
195 ret = HDR_2_CLIENT(p);
196
197 if (xmlMemTraceBlockAt == ret) {
199 "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
200 (long unsigned)size);
202 }
203
205
206 return(ret);
207}
#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 586 of file xmlmemory.c.

586 {
587 int res;
588
592 return(res);
593}
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 739 of file xmlmemory.c.

740{
741#ifdef MEM_LIST
742 MEMHDR *p;
743 unsigned idx;
744 int nb = 0;
745 time_t currentTime;
746 char buf[500];
747 struct tm * tstruct;
748#endif
749 FILE *old_fp = fp;
750
751 if (fp == NULL) {
752 fp = fopen(".memorylist", "w");
753 if (fp == NULL)
754 return;
755 }
756
757#ifdef MEM_LIST
758 currentTime = time(NULL);
759 tstruct = localtime(&currentTime);
760 strftime(buf, sizeof(buf) - 1, "%I:%M:%S %p", tstruct);
761 fprintf(fp," %s\n\n", buf);
762
763
764 fprintf(fp," MEMORY ALLOCATED : %lu, MAX was %lu\n",
766 fprintf(fp,"BLOCK NUMBER SIZE TYPE\n");
767 idx = 0;
769 p = memlist;
770 while (p) {
771 fprintf(fp,"%-5u %6lu %6lu ",idx++,p->mh_number,
772 (unsigned long)p->mh_size);
773 switch (p->mh_type) {
774 case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
775 case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
776 case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
777 case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
778 case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
779 default:
780 fprintf(fp,"Unknown memory block, may be corrupted");
782 if (old_fp == NULL)
783 fclose(fp);
784 return;
785 }
786 if (p->mh_file != NULL) fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
787 if (p->mh_tag != MEMTAG)
788 fprintf(fp," INVALID");
789 nb++;
790 if (nb < 100)
791 xmlMemContentShow(fp, p);
792 else
793 fprintf(fp," skip");
794
795 fprintf(fp,"\n");
796 p = p->mh_next;
797 }
799#else
800 fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
801#endif
802 if (old_fp == NULL)
803 fclose(fp);
804}
unsigned int idx
Definition: utils.c:41
__kernel_time_t time_t
Definition: linux.h:252
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
__u16 time
Definition: mkdosfs.c:8
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
size_t CDECL strftime(char *str, size_t max, const char *format, const struct tm *mstm)
Definition: strftime.c:293
Definition: time.h:68
#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 668 of file xmlmemory.c.

669{
670#ifdef MEM_LIST
671 MEMHDR *p;
672 unsigned idx;
673 int nb = 0;
674#endif
675 FILE *old_fp = fp;
676
677 if (nbBytes <= 0)
678 return;
679
680 if (fp == NULL) {
681 fp = fopen(".memorylist", "w");
682 if (fp == NULL)
683 return;
684 }
685
686#ifdef MEM_LIST
687 fprintf(fp," Last %li MEMORY ALLOCATED : %lu, MAX was %lu\n",
688 nbBytes, debugMemSize, debugMaxMemSize);
689 fprintf(fp,"BLOCK NUMBER SIZE TYPE\n");
690 idx = 0;
692 p = memlist;
693 while ((p) && (nbBytes > 0)) {
694 fprintf(fp,"%-5u %6lu %6lu ",idx++,p->mh_number,
695 (unsigned long)p->mh_size);
696 switch (p->mh_type) {
697 case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
698 case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
699 case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
700 case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
701 case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
702 default:
703 fprintf(fp,"Unknown memory block, may be corrupted");
705 if (old_fp == NULL)
706 fclose(fp);
707 return;
708 }
709 if (p->mh_file != NULL) fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
710 if (p->mh_tag != MEMTAG)
711 fprintf(fp," INVALID");
712 nb++;
713 if (nb < 100)
714 xmlMemContentShow(fp, p);
715 else
716 fprintf(fp," skip");
717
718 fprintf(fp,"\n");
719 nbBytes -= (unsigned long)p->mh_size;
720 p = p->mh_next;
721 }
723#else
724 fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
725#endif
726 if (old_fp == NULL)
727 fclose(fp);
728}
#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 414 of file xmlmemory.c.

415{
416 MEMHDR *p;
417 char *target;
418#ifdef DEBUG_MEMORY
419 size_t size;
420#endif
421
422 if (ptr == NULL)
423 return;
424
425 if (ptr == (void *) -1) {
427 "trying to free pointer from freed area\n");
428 goto error;
429 }
430
431 if (xmlMemTraceBlockAt == ptr) {
433 "%p : Freed()\n", xmlMemTraceBlockAt);
435 }
436
438
439 target = (char *) ptr;
440
441 p = CLIENT_2_HDR(ptr);
442 if (p->mh_tag != MEMTAG) {
443 Mem_Tag_Err(p);
444 goto error;
445 }
446 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
447 p->mh_tag = ~MEMTAG;
448 memset(target, -1, p->mh_size);
450 debugMemSize -= p->mh_size;
452#ifdef DEBUG_MEMORY
453 size = p->mh_size;
454#endif
455#ifdef MEM_LIST
456 debugmem_list_delete(p);
457#endif
459
460 free(p);
461
463
464#ifdef DEBUG_MEMORY
466 "Freed(%d) Ok\n", size);
467#endif
468
469 return;
470
471error:
473 "xmlMemFree(%p) error\n", ptr);
475 return;
476}
#define free
Definition: debug_ros.c:5
GLenum target
Definition: glext.h:7315
#define error(str)
Definition: mkdosfs.c:1605
static PVOID ptr
Definition: dispmode.c:27
#define memset(x, y, z)
Definition: compat.h:39
#define Mem_Tag_Err(a)
Definition: xmlmemory.c:113
#define CLIENT_2_HDR(a)
Definition: xmlmemory.c:97

Referenced by myFreeFunc(), myMallocFunc(), myReallocFunc(), and xmlInitializeGlobalState().

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

1061 {
1062 if (freeFunc != NULL) *freeFunc = xmlFree;
1063 if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
1064 if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
1065 if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
1066 return(0);
1067}

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

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

Referenced by myMallocFunc(), and xmlInitializeGlobalState().

◆ xmlMemoryDump()

void xmlMemoryDump ( void  )

xmlMemoryDump:

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

Definition at line 910 of file xmlmemory.c.

911{
912#ifdef MEM_LIST
913 FILE *dump;
914
915 if (debugMaxMemSize == 0)
916 return;
917 dump = fopen(".memdump", "w");
918 if (dump == NULL)
919 xmlMemoryDumpFile = stderr;
920 else xmlMemoryDumpFile = dump;
921
922 xmlMemDisplay(xmlMemoryDumpFile);
923
924 if (dump != NULL) fclose(dump);
925#endif /* MEM_LIST */
926}
static void dump(const void *ptr, unsigned len)
Definition: msc.c:95

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

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

555 {
556 return(xmlMemStrdupLoc(str, "none", 0));
557}
const WCHAR * str
char * xmlMemStrdupLoc(const char *str, const char *file, int line)
Definition: xmlmemory.c:490

Referenced by myStrdupFunc(), and xmlInitializeGlobalState().

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

403 {
404 return(xmlReallocLoc(ptr, size, "none", 0));
405}
void * xmlReallocLoc(void *ptr, size_t size, const char *file, int line)
Definition: xmlmemory.c:312

Referenced by myReallocFunc(), and xmlInitializeGlobalState().

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

1023 {
1024#ifdef DEBUG_MEMORY
1026 "xmlMemSetup()\n");
1027#endif
1028 if (freeFunc == NULL)
1029 return(-1);
1030 if (mallocFunc == NULL)
1031 return(-1);
1032 if (reallocFunc == NULL)
1033 return(-1);
1034 if (strdupFunc == NULL)
1035 return(-1);
1036 xmlFree = freeFunc;
1037 xmlMalloc = mallocFunc;
1038 xmlMallocAtomic = mallocFunc;
1039 xmlRealloc = reallocFunc;
1040 xmlMemStrdup = strdupFunc;
1041#ifdef DEBUG_MEMORY
1043 "xmlMemSetup() Ok\n");
1044#endif
1045 return(0);
1046}

Referenced by main().

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

866{
867#ifdef MEM_LIST
868 MEMHDR *p;
869#endif
870
871 if (fp != NULL)
872 fprintf(fp," MEMORY ALLOCATED : %lu, MAX was %lu\n",
874#ifdef MEM_LIST
876 if (nr > 0) {
877 fprintf(fp,"NUMBER SIZE TYPE WHERE\n");
878 p = memlist;
879 while ((p) && nr > 0) {
880 fprintf(fp,"%6lu %6lu ",p->mh_number,(unsigned long)p->mh_size);
881 switch (p->mh_type) {
882 case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
883 case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
884 case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
885 case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
886 case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
887 default:fprintf(fp," ??? in ");break;
888 }
889 if (p->mh_file != NULL)
890 fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
891 if (p->mh_tag != MEMTAG)
892 fprintf(fp," INVALID");
893 xmlMemContentShow(fp, p);
894 fprintf(fp,"\n");
895 nr--;
896 p = p->mh_next;
897 }
898 }
900#endif /* MEM_LIST */
901}
ULONG nr
Definition: thread.c:7

◆ xmlMemStrdupLoc()

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

Definition at line 490 of file xmlmemory.c.

491{
492 char *s;
493 size_t size = strlen(str) + 1;
494 MEMHDR *p;
495
498
499 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
501 "xmlMemStrdupLoc : Unsigned overflow\n");
503 return(NULL);
504 }
505
507 if (!p) {
508 goto error;
509 }
510 p->mh_tag = MEMTAG;
511 p->mh_size = size;
512 p->mh_type = STRDUP_TYPE;
513 p->mh_file = file;
514 p->mh_line = line;
516 p->mh_number = ++block;
520#ifdef MEM_LIST
521 debugmem_list_add(p);
522#endif
524
525 s = (char *) HDR_2_CLIENT(p);
526
527 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
528
529 strcpy(s,str);
530
532
533 if (xmlMemTraceBlockAt == s) {
535 "%p : Strdup() Ok\n", xmlMemTraceBlockAt);
537 }
538
539 return(s);
540
541error:
542 return(NULL);
543}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLdouble s
Definition: gl.h:2039

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

568 {
569 int res;
570
574 return(res);
575}

Referenced by myMallocFunc(), myReallocFunc(), and myStrdupFunc().

◆ xmlReallocLoc()

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

Definition at line 312 of file xmlmemory.c.

313{
314 MEMHDR *p, *tmp;
315 unsigned long number;
316#ifdef DEBUG_MEMORY
317 size_t oldsize;
318#endif
319
320 if (ptr == NULL)
321 return(xmlMallocLoc(size, file, line));
322
325
326 p = CLIENT_2_HDR(ptr);
327 number = p->mh_number;
329 if (p->mh_tag != MEMTAG) {
330 Mem_Tag_Err(p);
331 goto error;
332 }
333 p->mh_tag = ~MEMTAG;
335 debugMemSize -= p->mh_size;
337#ifdef DEBUG_MEMORY
338 oldsize = p->mh_size;
339#endif
340#ifdef MEM_LIST
341 debugmem_list_delete(p);
342#endif
344
345 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
347 "xmlReallocLoc : Unsigned overflow\n");
349 return(NULL);
350 }
351
352 tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
353 if (!tmp) {
354 free(p);
355 goto error;
356 }
357 p = tmp;
358 if (xmlMemTraceBlockAt == ptr) {
360 "%p : Realloced(%lu -> %lu) Ok\n",
361 xmlMemTraceBlockAt, (long unsigned)p->mh_size,
362 (long unsigned)size);
364 }
365 p->mh_tag = MEMTAG;
366 p->mh_number = number;
367 p->mh_type = REALLOC_TYPE;
368 p->mh_size = size;
369 p->mh_file = file;
370 p->mh_line = line;
375#ifdef MEM_LIST
376 debugmem_list_add(p);
377#endif
379
381
382#ifdef DEBUG_MEMORY
384 "Realloced(%d to %d) Ok\n", oldsize, size);
385#endif
386 return(HDR_2_CLIENT(p));
387
388error:
389 return(NULL);
390}
#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 __find_get_block(), __getblk(), _chm_decompress_block(), _chm_get_cmpblock_bounds(), absynth_1to1_i486(), add_block(), add_block_index(), add_data_block(), add_data_to_folder(), add_typeinfo_block(), adns__transfer_interim(), tinyxml2::MemPoolT< SIZE >::Alloc(), alloc_pioinfo_block(), allocate_block(), append_data(), AVIFILE_SamplesToBlock(), Base64ToBinary(), blake2b_compress(), block_size(), BlockChainStream_GetBlockAtOffset(), chksum_crc32(), codeview_snarf(), copy_data_blocks(), create_io_inherit_block(), create_library_block(), ctl2_alloc_segment(), d3dx_effect_ApplyParameterBlock(), d3dx_effect_cleanup(), decode_mcu(), decode_mcu_AC_first(), decode_mcu_AC_refine(), decode_mcu_DC_first(), decode_mcu_sub(), desfunc(), 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(), fill_delegated_proxy_table(), fill_delegated_stub_table(), fill_stubless_table(), 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(), hash(), htest_one_block(), IAVIStream_fnRead(), idx_to_block(), III_hybrid(), ImmDestroyIMCC(), ldap_memfreeA(), ldap_memfreeW(), map_bh(), ntom_ins2outs(), OleUnblockServer(), ParseSharedPacket(), pending_flush(), record_parameter(), sb_bread(), sb_find_get_block(), sb_getblk(), sb_getblk_zero(), set_cache_glyph(), set_cache_glyph_widths(), sltg_add_typeinfo(), sltg_write_header(), sltg_write_typeinfo(), 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(), tcpip_callback_with_block(), test_effect_parameter_block(), test_FDICopy(), test_fdsa(), UDFProcessSequence(), UDFReadVDS(), UDFUpdateVDS(), UDFVerifySequence(), urlcache_entry_alloc(), urlcache_entry_free(), write_data_blocks(), xmlMallocAtomicLoc(), xmlMallocLoc(), and xmlMemStrdupLoc().

◆ debugMaxMemSize

◆ debugMemBlocks

unsigned long debugMemBlocks = 0
static

◆ debugMemSize

◆ xmlMemInitialized

int xmlMemInitialized = 0
static

MEM_LIST:

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

Definition at line 34 of file xmlmemory.c.

Referenced by xmlCleanupMemory(), xmlInitMemory(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemStrdupLoc(), and xmlReallocLoc().

◆ xmlMemMutex

◆ xmlMemStopAtBlock

unsigned int xmlMemStopAtBlock = 0
static

◆ xmlMemTraceBlockAt

void* xmlMemTraceBlockAt = NULL
static