diff options
author | David Robillard <d@drobilla.net> | 2022-11-15 15:16:47 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-11-16 10:52:09 -0500 |
commit | 89230a893502f0a25984201e7bef9d84bb07aac7 (patch) | |
tree | 424e6c07bd4bb6205fad03a90e199a692773c17f | |
parent | 117391dcf4358e82c85e482340859f5b5dbb2aa8 (diff) | |
download | jalv-89230a893502f0a25984201e7bef9d84bb07aac7.tar.gz jalv-89230a893502f0a25984201e7bef9d84bb07aac7.tar.bz2 jalv-89230a893502f0a25984201e7bef9d84bb07aac7.zip |
Fix potential memory leaks
-rw-r--r-- | src/symap.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/symap.c b/src/symap.c index b034bd0..07002f2 100644 --- a/src/symap.c +++ b/src/symap.c @@ -145,15 +145,18 @@ symap_map(Symap* const map, const char* sym) return 0; } + map->symbols = new_symbols; + // Grow index array uint32_t* new_index = (uint32_t*)realloc(map->index, id * sizeof(index)); if (!new_index) { return 0; } + map->index = new_index; + // Append new symbol to symbols array map->size = id; - map->symbols = new_symbols; map->symbols[id - 1] = symap_strdup(sym); // Insert new index element into sorted index @@ -212,6 +215,10 @@ symap_test(Symap* const map) } const uint32_t id = symap_map(map, syms[i]); + if (!id) { + return fprintf(stderr, "error: Failed to insert ID\n"); + } + if (!!strcmp(map->symbols[id - 1], syms[i])) { return fprintf(stderr, "error: Corrupt symbol table\n"); } |