| 309 | */ |
| 310 | |
| 311 | void * |
| 312 | xmlReallocLoc(void *ptr,size_t size, const char * file, int line) |
| 313 | { |
| 314 | MEMHDR *p; |
| 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 | |
| 323 | if (!xmlMemInitialized) xmlInitMemory(); |
| 324 | TEST_POINT |
| 325 | |
| 326 | p = CLIENT_2_HDR(ptr); |
| 327 | number = p->mh_number; |
| 328 | if (xmlMemStopAtBlock == number) xmlMallocBreakpoint(); |
| 329 | if (p->mh_tag != MEMTAG) { |
| 330 | Mem_Tag_Err(p); |
| 331 | goto error; |
| 332 | } |
| 333 | p->mh_tag = ~MEMTAG; |
| 334 | xmlMutexLock(xmlMemMutex); |
| 335 | debugMemSize -= p->mh_size; |
| 336 | debugMemBlocks--; |
| 337 | #ifdef DEBUG_MEMORY |
| 338 | oldsize = p->mh_size; |
| 339 | #endif |
| 340 | #ifdef MEM_LIST |
| 341 | debugmem_list_delete(p); |
| 342 | #endif |
| 343 | xmlMutexUnlock(xmlMemMutex); |
| 344 | |
| 345 | p = (MEMHDR *) realloc(p,RESERVE_SIZE+size); |
| 346 | if (!p) { |
| 347 | goto error; |
| 348 | } |
| 349 | if (xmlMemTraceBlockAt == ptr) { |
| 350 | xmlGenericError(xmlGenericErrorContext, |
| 351 | "%p : Realloced(%d -> %d) Ok\n", |
| 352 | xmlMemTraceBlockAt, p->mh_size, size); |
| 353 | xmlMallocBreakpoint(); |
| 354 | } |
| 355 | p->mh_tag = MEMTAG; |
| 356 | p->mh_number = number; |
| 357 | p->mh_type = REALLOC_TYPE; |
| 358 | p->mh_size = size; |
| 359 | p->mh_file = file; |
| 360 | p->mh_line = line; |
| 361 | xmlMutexLock(xmlMemMutex); |
| 362 | debugMemSize += size; |
| 363 | debugMemBlocks++; |
| 364 | if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize; |
| 365 | #ifdef MEM_LIST |
| 366 | debugmem_list_add(p); |
| 367 | #endif |
| 368 | xmlMutexUnlock(xmlMemMutex); |
no test coverage detected