diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-03-23 10:32:44 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-03-23 10:32:44 -0400 |
| commit | 5a4af40b74600a56823e37744588419f067f46d5 (patch) | |
| tree | 9c4eadd0592ae2221045d1278fe5bb3b28a6655e /src | |
| parent | 4ed9ec9fc5155508102da67829cf7fec9e92a50a (diff) | |
| download | omnisearch-5a4af40b74600a56823e37744588419f067f46d5.tar.gz | |
fix: fix leaks in add_link_to_collection on fail
Diffstat (limited to 'src')
| -rw-r--r-- | src/Routes/Search.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/Routes/Search.c b/src/Routes/Search.c index baf0fdf..5c94e5b 100644 --- a/src/Routes/Search.c +++ b/src/Routes/Search.c @@ -189,6 +189,8 @@ static int add_infobox_to_collection(InfoBox *infobox, char ****collection, static int add_link_to_collection(const char *href, const char *label, const char *class_name, char ****collection, int **inner_counts, int current_count) { + char ***old_collection = *collection; + int *old_inner_counts = *inner_counts; char ***new_collection = (char ***)malloc(sizeof(char **) * (current_count + 1)); int *new_inner_counts = @@ -207,16 +209,18 @@ static int add_link_to_collection(const char *href, const char *label, memcpy(new_inner_counts, *inner_counts, sizeof(int) * current_count); } - free(*collection); - free(*inner_counts); - *collection = new_collection; *inner_counts = new_inner_counts; (*collection)[current_count] = (char **)malloc(sizeof(char *) * LINK_FIELD_COUNT); - if (!(*collection)[current_count]) + if (!(*collection)[current_count]) { + *collection = old_collection; + *inner_counts = old_inner_counts; + free(new_collection); + free(new_inner_counts); return current_count; + } (*collection)[current_count][0] = strdup(href ? href : ""); (*collection)[current_count][1] = strdup(label ? label : ""); @@ -228,10 +232,17 @@ static int add_link_to_collection(const char *href, const char *label, free((*collection)[current_count][1]); free((*collection)[current_count][2]); free((*collection)[current_count]); + *collection = old_collection; + *inner_counts = old_inner_counts; + free(new_collection); + free(new_inner_counts); return current_count; } (*inner_counts)[current_count] = LINK_FIELD_COUNT; + + free(old_collection); + free(old_inner_counts); return current_count + 1; } |
