summaryrefslogtreecommitdiff
path: root/chromium/third_party/libxml/src/xmlmemory.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/libxml/src/xmlmemory.c')
-rw-r--r--chromium/third_party/libxml/src/xmlmemory.c179
1 files changed, 54 insertions, 125 deletions
diff --git a/chromium/third_party/libxml/src/xmlmemory.c b/chromium/third_party/libxml/src/xmlmemory.c
index 892d50c306d..eed166693e9 100644
--- a/chromium/third_party/libxml/src/xmlmemory.c
+++ b/chromium/third_party/libxml/src/xmlmemory.c
@@ -31,11 +31,13 @@
#include <libxml/xmlerror.h>
#include <libxml/threads.h>
-static int xmlMemInitialized = 0;
+#include "private/memory.h"
+#include "private/threads.h"
+
static unsigned long debugMemSize = 0;
static unsigned long debugMemBlocks = 0;
static unsigned long debugMaxMemSize = 0;
-static xmlMutexPtr xmlMemMutex = NULL;
+static xmlMutex xmlMemMutex;
void xmlMallocBreakpoint(void);
@@ -147,7 +149,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
MEMHDR *p;
void *ret;
- if (!xmlMemInitialized) xmlInitMemory();
+ xmlInitParser();
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"Malloc(%d)\n",size);
@@ -175,7 +177,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
p->mh_type = MALLOC_TYPE;
p->mh_file = file;
p->mh_line = line;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
p->mh_number = ++block;
debugMemSize += size;
debugMemBlocks++;
@@ -183,7 +185,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
#ifdef MEM_LIST
debugmem_list_add(p);
#endif
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
@@ -223,7 +225,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
MEMHDR *p;
void *ret;
- if (!xmlMemInitialized) xmlInitMemory();
+ xmlInitParser();
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"Malloc(%d)\n",size);
@@ -251,7 +253,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
p->mh_type = MALLOC_ATOMIC_TYPE;
p->mh_file = file;
p->mh_line = line;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
p->mh_number = ++block;
debugMemSize += size;
debugMemBlocks++;
@@ -259,7 +261,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
#ifdef MEM_LIST
debugmem_list_add(p);
#endif
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
@@ -320,7 +322,7 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
if (ptr == NULL)
return(xmlMallocLoc(size, file, line));
- if (!xmlMemInitialized) xmlInitMemory();
+ xmlInitParser();
TEST_POINT
p = CLIENT_2_HDR(ptr);
@@ -331,7 +333,7 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
goto error;
}
p->mh_tag = ~MEMTAG;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
debugMemSize -= p->mh_size;
debugMemBlocks--;
#ifdef DEBUG_MEMORY
@@ -340,7 +342,7 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
#ifdef MEM_LIST
debugmem_list_delete(p);
#endif
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
@@ -368,14 +370,14 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
p->mh_size = size;
p->mh_file = file;
p->mh_line = line;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
debugMemSize += size;
debugMemBlocks++;
if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
#ifdef MEM_LIST
debugmem_list_add(p);
#endif
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
TEST_POINT
@@ -446,7 +448,7 @@ xmlMemFree(void *ptr)
if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
p->mh_tag = ~MEMTAG;
memset(target, -1, p->mh_size);
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
debugMemSize -= p->mh_size;
debugMemBlocks--;
#ifdef DEBUG_MEMORY
@@ -455,7 +457,7 @@ xmlMemFree(void *ptr)
#ifdef MEM_LIST
debugmem_list_delete(p);
#endif
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
free(p);
@@ -493,7 +495,7 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
size_t size = strlen(str) + 1;
MEMHDR *p;
- if (!xmlMemInitialized) xmlInitMemory();
+ xmlInitParser();
TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
@@ -512,7 +514,7 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
p->mh_type = STRDUP_TYPE;
p->mh_file = file;
p->mh_line = line;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
p->mh_number = ++block;
debugMemSize += size;
debugMemBlocks++;
@@ -520,7 +522,7 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
#ifdef MEM_LIST
debugmem_list_add(p);
#endif
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
s = (char *) HDR_2_CLIENT(p);
@@ -566,12 +568,7 @@ xmlMemoryStrdup(const char *str) {
int
xmlMemUsed(void) {
- int res;
-
- xmlMutexLock(xmlMemMutex);
- res = debugMemSize;
- xmlMutexUnlock(xmlMemMutex);
- return(res);
+ return(debugMemSize);
}
/**
@@ -586,74 +583,12 @@ int
xmlMemBlocks(void) {
int res;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
res = debugMemBlocks;
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
return(res);
}
-#ifdef MEM_LIST
-/**
- * xmlMemContentShow:
- * @fp: a FILE descriptor used as the output file
- * @p: a memory block header
- *
- * tries to show some content from the memory block
- */
-
-static void
-xmlMemContentShow(FILE *fp, MEMHDR *p)
-{
- int i,j,k,len;
- const char *buf;
-
- if (p == NULL) {
- fprintf(fp, " NULL");
- return;
- }
- len = p->mh_size;
- buf = (const char *) HDR_2_CLIENT(p);
-
- for (i = 0;i < len;i++) {
- if (buf[i] == 0) break;
- if (!isprint((unsigned char) buf[i])) break;
- }
- if ((i < 4) && ((buf[i] != 0) || (i == 0))) {
- if (len >= 4) {
- MEMHDR *q;
- void *cur;
-
- for (j = 0;(j < len -3) && (j < 40);j += 4) {
- cur = *((void **) &buf[j]);
- q = CLIENT_2_HDR(cur);
- p = memlist;
- k = 0;
- while (p != NULL) {
- if (p == q) break;
- p = p->mh_next;
- if (k++ > 100) break;
- }
- if ((p != NULL) && (p == q)) {
- fprintf(fp, " pointer to #%lu at index %d",
- p->mh_number, j);
- return;
- }
- }
- }
- } else if ((i == 0) && (buf[i] == 0)) {
- fprintf(fp," null");
- } else {
- if (buf[i] == 0) fprintf(fp," \"%.25s\"", buf);
- else {
- fprintf(fp," [");
- for (j = 0;j < i;j++)
- fprintf(fp,"%c", buf[j]);
- fprintf(fp,"]");
- }
- }
-}
-#endif
-
/**
* xmlMemDisplayLast:
* @fp: a FILE descriptor used as the output file, if NULL, the result is
@@ -688,7 +623,7 @@ xmlMemDisplayLast(FILE *fp, long nbBytes)
nbBytes, debugMemSize, debugMaxMemSize);
fprintf(fp,"BLOCK NUMBER SIZE TYPE\n");
idx = 0;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
p = memlist;
while ((p) && (nbBytes > 0)) {
fprintf(fp,"%-5u %6lu %6lu ",idx++,p->mh_number,
@@ -701,7 +636,7 @@ xmlMemDisplayLast(FILE *fp, long nbBytes)
case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
default:
fprintf(fp,"Unknown memory block, may be corrupted");
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
if (old_fp == NULL)
fclose(fp);
return;
@@ -710,16 +645,12 @@ xmlMemDisplayLast(FILE *fp, long nbBytes)
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
nb++;
- if (nb < 100)
- xmlMemContentShow(fp, p);
- else
- fprintf(fp," skip");
fprintf(fp,"\n");
nbBytes -= (unsigned long)p->mh_size;
p = p->mh_next;
}
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
#else
fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
#endif
@@ -765,7 +696,7 @@ xmlMemDisplay(FILE *fp)
debugMemSize, debugMaxMemSize);
fprintf(fp,"BLOCK NUMBER SIZE TYPE\n");
idx = 0;
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
p = memlist;
while (p) {
fprintf(fp,"%-5u %6lu %6lu ",idx++,p->mh_number,
@@ -778,7 +709,7 @@ xmlMemDisplay(FILE *fp)
case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
default:
fprintf(fp,"Unknown memory block, may be corrupted");
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
if (old_fp == NULL)
fclose(fp);
return;
@@ -787,15 +718,11 @@ xmlMemDisplay(FILE *fp)
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
nb++;
- if (nb < 100)
- xmlMemContentShow(fp, p);
- else
- fprintf(fp," skip");
fprintf(fp,"\n");
p = p->mh_next;
}
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
#else
fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
#endif
@@ -872,7 +799,7 @@ xmlMemShow(FILE *fp, int nr ATTRIBUTE_UNUSED)
fprintf(fp," MEMORY ALLOCATED : %lu, MAX was %lu\n",
debugMemSize, debugMaxMemSize);
#ifdef MEM_LIST
- xmlMutexLock(xmlMemMutex);
+ xmlMutexLock(&xmlMemMutex);
if (nr > 0) {
fprintf(fp,"NUMBER SIZE TYPE WHERE\n");
p = memlist;
@@ -890,13 +817,12 @@ xmlMemShow(FILE *fp, int nr ATTRIBUTE_UNUSED)
fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
- xmlMemContentShow(fp, p);
fprintf(fp,"\n");
nr--;
p = p->mh_next;
}
}
- xmlMutexUnlock(xmlMemMutex);
+ xmlMutexUnlock(&xmlMemMutex);
#endif /* MEM_LIST */
}
@@ -935,28 +861,29 @@ xmlMemoryDump(void)
/**
* xmlInitMemory:
*
- * DEPRECATED: This function will be made private. Call xmlInitParser to
- * initialize the library.
+ * DEPRECATED: Alias for xmlInitParser.
+ */
+int
+xmlInitMemory(void) {
+ xmlInitParser();
+ return(0);
+}
+
+/**
+ * xmlInitMemoryInternal:
*
* Initialize the memory layer.
*
* Returns 0 on success
*/
-int
-xmlInitMemory(void)
-{
+void
+xmlInitMemoryInternal(void) {
char *breakpoint;
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"xmlInitMemory()\n");
#endif
- /*
- This is really not good code (see Bug 130419). Suggestions for
- improvement will be welcome!
- */
- if (xmlMemInitialized) return(-1);
- xmlMemInitialized = 1;
- xmlMemMutex = xmlNewMutex();
+ xmlInitMutex(&xmlMemMutex);
breakpoint = getenv("XML_MEM_BREAKPOINT");
if (breakpoint != NULL) {
@@ -971,32 +898,34 @@ xmlInitMemory(void)
xmlGenericError(xmlGenericErrorContext,
"xmlInitMemory() Ok\n");
#endif
- return(0);
}
/**
* xmlCleanupMemory:
*
- * DEPRECATED: This function will be made private. Call xmlCleanupParser
+ * 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.
+ */
+void
+xmlCleanupMemory(void) {
+}
+
+/**
+ * xmlCleanupMemoryInternal:
*
* Free up all the memory allocated by the library for its own
* use. This should not be called by user level code.
*/
void
-xmlCleanupMemory(void) {
+xmlCleanupMemoryInternal(void) {
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"xmlCleanupMemory()\n");
#endif
- if (xmlMemInitialized == 0)
- return;
- xmlFreeMutex(xmlMemMutex);
- xmlMemMutex = NULL;
- xmlMemInitialized = 0;
+ xmlCleanupMutex(&xmlMemMutex);
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"xmlCleanupMemory() Ok\n");