diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-04-26 22:40:43 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-04-26 22:40:43 +0200 |
| commit | 3413d878a7b1a37ff362ddfa9141349e73af917a (patch) | |
| tree | d15e1795fc697944fb1ba1a2b8a2793db1ac4707 /src/zsetup.c | |
| parent | Zahl[en] is spelled with upper case Z (diff) | |
| download | libzahl-3413d878a7b1a37ff362ddfa9141349e73af917a.tar.gz libzahl-3413d878a7b1a37ff362ddfa9141349e73af917a.tar.bz2 libzahl-3413d878a7b1a37ff362ddfa9141349e73af917a.tar.xz | |
Ensure that failure does not result in memory leak
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zsetup.c')
| -rw-r--r-- | src/zsetup.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/zsetup.c b/src/zsetup.c index 10fc5f5..e36bff3 100644 --- a/src/zsetup.c +++ b/src/zsetup.c @@ -15,6 +15,9 @@ int libzahl_error; zahl_char_t **libzahl_pool[sizeof(size_t) * 8]; size_t libzahl_pool_n[sizeof(size_t) * 8]; 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 @@ -23,7 +26,7 @@ zsetup(jmp_buf env) size_t i; *libzahl_jmp_buf = *env; - if (!libzahl_set_up) { + if (likely(!libzahl_set_up)) { libzahl_set_up = 1; memset(libzahl_pool, 0, sizeof(libzahl_pool)); @@ -40,5 +43,14 @@ zsetup(jmp_buf env) #undef X for (i = BITS_PER_CHAR; i--;) zinit(libzahl_tmp_divmod_ds[i]); + + libzahl_temp_stack = malloc(256 * sizeof(*libzahl_temp_stack)); + if (unlikely(!libzahl_temp_stack)) { + if (!errno) /* sigh... */ + errno = ENOMEM; + libzahl_failure(errno); + } + libzahl_temp_stack_head = libzahl_temp_stack; + libzahl_temp_stack_end = libzahl_temp_stack + 256; } } |
