rolled back to 2.9.1 because 2.9.2 doesn't work with connecting net
[platform/upstream/libxml2.git] / xmlmemory.c
index f08c8c3..25d9318 100644 (file)
@@ -109,7 +109,6 @@ typedef struct memnod {
 #define RESERVE_SIZE (((HDR_SIZE + (ALIGN_SIZE-1)) \
                      / ALIGN_SIZE ) * ALIGN_SIZE)
 
-#define MAX_SIZE_T ((size_t)-1)
 
 #define CLIENT_2_HDR(a) ((MEMHDR *) (((char *) (a)) - RESERVE_SIZE))
 #define HDR_2_CLIENT(a)    ((void *) (((char *) (a)) + RESERVE_SIZE))
@@ -218,7 +217,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
 
 /**
  * xmlMallocAtomicLoc:
- * @size:  an unsigned int specifying the size in byte to allocate.
+ * @size:  an int specifying the size in byte to allocate.
  * @file:  the file name or NULL
  * @line:  the line number
  *
@@ -241,18 +240,11 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
 
     TEST_POINT
 
-    if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
-       xmlGenericError(xmlGenericErrorContext,
-               "xmlMallocAtomicLoc : Unsigned overflow prevented\n");
-       xmlMemoryDump();
-       return(NULL);
-    }
-
     p = (MEMHDR *) malloc(RESERVE_SIZE+size);
 
     if (!p) {
        xmlGenericError(xmlGenericErrorContext,
-               "xmlMallocAtomicLoc : Out of free space\n");
+               "xmlMallocLoc : Out of free space\n");
        xmlMemoryDump();
        return(NULL);
     }
@@ -321,7 +313,7 @@ xmlMemMalloc(size_t size)
 void *
 xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
 {
-    MEMHDR *p, *tmp;
+    MEMHDR *p;
     unsigned long number;
 #ifdef DEBUG_MEMORY
     size_t oldsize;
@@ -352,12 +344,10 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
 #endif
     xmlMutexUnlock(xmlMemMutex);
 
-    tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
-    if (!tmp) {
-        free(p);
+    p = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
+    if (!p) {
         goto error;
     }
-    p = tmp;
     if (xmlMemTraceBlockAt == ptr) {
        xmlGenericError(xmlGenericErrorContext,
                        "%p : Realloced(%lu -> %lu) Ok\n",
@@ -522,7 +512,10 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
 
     if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
 
-    strcpy(s,str);
+    if (s != NULL)
+      strcpy(s,str);
+    else
+      goto error;
 
     TEST_POINT
 
@@ -562,12 +555,7 @@ xmlMemoryStrdup(const char *str) {
 
 int
 xmlMemUsed(void) {
-    int res;
-
-    xmlMutexLock(xmlMemMutex);
-    res = debugMemSize;
-    xmlMutexUnlock(xmlMemMutex);
-    return(res);
+     return(debugMemSize);
 }
 
 /**
@@ -580,12 +568,7 @@ xmlMemUsed(void) {
 
 int
 xmlMemBlocks(void) {
-    int res;
-
-    xmlMutexLock(xmlMemMutex);
-    res = debugMemBlocks;
-    xmlMutexUnlock(xmlMemMutex);
-    return(res);
+     return(debugMemBlocks);
 }
 
 #ifdef MEM_LIST
@@ -600,15 +583,13 @@ xmlMemBlocks(void) {
 static void
 xmlMemContentShow(FILE *fp, MEMHDR *p)
 {
-    int i,j,k,len;
-    const char *buf;
+    int i,j,k,len = p->mh_size;
+    const char *buf = (const char *) HDR_2_CLIENT(p);
 
     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;