commit 54a9d9a38a6fd9c4ee7c508a168c1f78391644cb
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Wed Apr 27 00:43:30 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Wed Apr 27 00:43:30 2016 +0200
Fix possible memory in zstr on failure
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/src/internals.h b/src/internals.h
index 40dd74d..225d64c 100644
--- a/src/internals.h
+++ b/src/internals.h
_AT_@ -92,6 +92,7 @@ extern size_t libzahl_pool_alloc[sizeof(size_t) * 8];
extern struct zahl **libzahl_temp_stack;
extern struct zahl **libzahl_temp_stack_head;
extern struct zahl **libzahl_temp_stack_end;
+extern void *libzahl_temp_allocation;
#define likely(expr) ZAHL_LIKELY(expr)
#define unlikely(expr) ZAHL_UNLIKELY(expr)
_AT_@ -131,6 +132,8 @@ libzahl_failure(int error)
if (libzahl_temp_stack)
while (libzahl_temp_stack_head != libzahl_temp_stack)
zfree(*--libzahl_temp_stack_head);
+ free(libzahl_temp_allocation);
+ libzahl_temp_allocation = 0;
longjmp(libzahl_jmp_buf, 1);
}
diff --git a/src/zsetup.c b/src/zsetup.c
index 212a1e9..aebef32 100644
--- a/src/zsetup.c
+++ b/src/zsetup.c
_AT_@ -18,6 +18,7 @@ size_t libzahl_pool_alloc[sizeof(size_t) * 8];
struct zahl **libzahl_temp_stack;
struct zahl **libzahl_temp_stack_head;
struct zahl **libzahl_temp_stack_end;
+void *libzahl_temp_allocation = 0;
void
diff --git a/src/zstr.c b/src/zstr.c
index 308c7ef..6a577b9 100644
--- a/src/zstr.c
+++ b/src/zstr.c
_AT_@ -81,7 +81,7 @@ zstr(z_t a, char *b, size_t n)
n = zstr_length(a, 10);
}
- if (unlikely(!b) && unlikely(!(b = malloc(n + 1))))
+ if (unlikely(!b) && unlikely(!(b = libzahl_temp_allocation = malloc(n + 1))))
libzahl_memfailure();
neg = znegative(a);
_AT_@ -111,5 +111,6 @@ zstr(z_t a, char *b, size_t n)
}
}
+ libzahl_temp_allocation = 0;
return b - neg;
}
Received on Wed Apr 27 2016 - 00:44:13 CEST
This archive was generated by hypermail 2.3.0
: Wed Apr 27 2016 - 00:48:21 CEST