[libxml2] xmlmemory: handle realloc properly
- From: Daniel Veillard <veillard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] xmlmemory: handle realloc properly
- Date: Mon, 13 Oct 2014 14:41:08 +0000 (UTC)
commit 7446445dec0e46a5af821e57fa5ee04405666efd
Author: Yegor Yefremov <yegorslists googlemail com>
Date: Fri Oct 10 12:23:09 2014 +0200
xmlmemory: handle realloc properly
If realloc fails, free original pointer.
Signed-off-by: Yegor Yefremov <yegorslists googlemail com>
xmlmemory.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/xmlmemory.c b/xmlmemory.c
index 05084e3..a3dc737 100644
--- a/xmlmemory.c
+++ b/xmlmemory.c
@@ -313,7 +313,7 @@ xmlMemMalloc(size_t size)
void *
xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
{
- MEMHDR *p;
+ MEMHDR *p, *tmp;
unsigned long number;
#ifdef DEBUG_MEMORY
size_t oldsize;
@@ -344,10 +344,12 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
#endif
xmlMutexUnlock(xmlMemMutex);
- p = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
- if (!p) {
+ tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
+ if (!tmp) {
+ free(p);
goto error;
}
+ p = tmp;
if (xmlMemTraceBlockAt == ptr) {
xmlGenericError(xmlGenericErrorContext,
"%p : Realloced(%lu -> %lu) Ok\n",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]