* 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. */
| 152 | * Returns a pointer to the allocated area or NULL in case of lack of memory. |
| 153 | */ |
| 154 | void * |
| 155 | xmlMemRealloc(void *ptr, size_t size) { |
| 156 | MEMHDR *p, *tmp; |
| 157 | size_t oldSize; |
| 158 | |
| 159 | if (ptr == NULL) |
| 160 | return(xmlMemMalloc(size)); |
| 161 | |
| 162 | xmlInitParser(); |
| 163 | |
| 164 | if (size > (MAX_SIZE_T - RESERVE_SIZE)) { |
| 165 | fprintf(stderr, "xmlMemRealloc: Unsigned overflow\n"); |
| 166 | return(NULL); |
| 167 | } |
| 168 | |
| 169 | p = CLIENT_2_HDR(ptr); |
| 170 | if (p->mh_tag != MEMTAG) { |
| 171 | fprintf(stderr, "xmlMemRealloc: Tag error\n"); |
| 172 | return(NULL); |
| 173 | } |
| 174 | oldSize = p->mh_size; |
| 175 | p->mh_tag = ~MEMTAG; |
| 176 | |
| 177 | tmp = (MEMHDR *) realloc(p, RESERVE_SIZE + size); |
| 178 | if (!tmp) { |
| 179 | p->mh_tag = MEMTAG; |
| 180 | fprintf(stderr, "xmlMemRealloc: Out of memory\n"); |
| 181 | return(NULL); |
| 182 | } |
| 183 | p = tmp; |
| 184 | p->mh_tag = MEMTAG; |
| 185 | p->mh_size = size; |
| 186 | |
| 187 | xmlMutexLock(&xmlMemMutex); |
| 188 | debugMemSize -= oldSize; |
| 189 | debugMemSize += size; |
| 190 | xmlMutexUnlock(&xmlMemMutex); |
| 191 | |
| 192 | return(HDR_2_CLIENT(p)); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * xmlMemFree: |
no test coverage detected