* 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. */
| 97 | * Returns a pointer to the allocated area or NULL in case of lack of memory. |
| 98 | */ |
| 99 | void * |
| 100 | xmlMemMalloc(size_t size) |
| 101 | { |
| 102 | MEMHDR *p; |
| 103 | |
| 104 | xmlInitParser(); |
| 105 | |
| 106 | if (size > (MAX_SIZE_T - RESERVE_SIZE)) { |
| 107 | fprintf(stderr, "xmlMemMalloc: Unsigned overflow\n"); |
| 108 | return(NULL); |
| 109 | } |
| 110 | |
| 111 | p = (MEMHDR *) malloc(RESERVE_SIZE + size); |
| 112 | if (!p) { |
| 113 | fprintf(stderr, "xmlMemMalloc: Out of memory\n"); |
| 114 | return(NULL); |
| 115 | } |
| 116 | p->mh_tag = MEMTAG; |
| 117 | p->mh_size = size; |
| 118 | |
| 119 | xmlMutexLock(&xmlMemMutex); |
| 120 | debugMemSize += size; |
| 121 | debugMemBlocks++; |
| 122 | xmlMutexUnlock(&xmlMemMutex); |
| 123 | |
| 124 | return(HDR_2_CLIENT(p)); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * xmlReallocLoc: |
no test coverage detected