diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-03-13 22:28:52 +0000 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-03-13 22:28:52 +0000 |
| commit | 27899706fbfa1ceff1af7e3377e84748aa89fab3 (patch) | |
| tree | 8171aa57ffd25ad0b0ae25533ada1e3d2346eb72 | |
| parent | 8d9588a44ffd4e55a402c6fcbc80cea04b4fe4d4 (diff) | |
| download | omnisearch-27899706fbfa1ceff1af7e3377e84748aa89fab3.tar.gz | |
fix: null checks after some malloc allocations
| -rw-r--r-- | src/Routes/Images.c | 7 | ||||
| -rw-r--r-- | src/Routes/Search.c | 25 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/Routes/Images.c b/src/Routes/Images.c index 5f8cf2c..7536f6b 100644 --- a/src/Routes/Images.c +++ b/src/Routes/Images.c @@ -118,6 +118,12 @@ int images_handler(UrlParams *params) { int max_images = (nodes < 32) ? nodes : 32; image_matrix = malloc(sizeof(char **) * max_images); inner_counts = malloc(sizeof(int) * max_images); + if (!image_matrix || !inner_counts) { + if (image_matrix) free(image_matrix); + if (inner_counts) free(inner_counts); + image_matrix = NULL; + inner_counts = NULL; + } for (int i = 0; i < nodes; i++) { if (image_count >= 32) @@ -224,6 +230,7 @@ int images_handler(UrlParams *params) { image_matrix[image_count] = malloc(sizeof(char *) * 4); image_matrix[image_count][0] = proxy_url ? strdup(proxy_url) : strdup((char *)iurl); + free(proxy_url); image_matrix[image_count][1] = strdup(title ? (char *)title : "Image"); image_matrix[image_count][2] = strdup(rurl ? (char *)rurl : "#"); image_matrix[image_count][3] = diff --git a/src/Routes/Search.c b/src/Routes/Search.c index 5e76d7d..6fa3157 100644 --- a/src/Routes/Search.c +++ b/src/Routes/Search.c @@ -266,6 +266,18 @@ int results_handler(UrlParams *params) { char ***results_matrix = (char ***)malloc(sizeof(char **) * total_results); int *results_inner_counts = (int *)malloc(sizeof(int) * total_results); char **seen_urls = (char **)malloc(sizeof(char *) * total_results); + if (!results_matrix || !results_inner_counts || !seen_urls) { + if (results_matrix) free(results_matrix); + if (results_inner_counts) free(results_inner_counts); + if (seen_urls) free(seen_urls); + char *html = render_template("results.html", &ctx); + if (html) { + send_response(html); + free(html); + } + free_context(&ctx); + return 0; + } int unique_count = 0; for (int i = 0; i < ENGINE_COUNT; i++) { @@ -288,8 +300,21 @@ int results_handler(UrlParams *params) { } seen_urls[unique_count] = strdup(display_url); + if (!seen_urls[unique_count]) { + free(all_results[i][j].url); + free(all_results[i][j].title); + free(all_results[i][j].snippet); + continue; + } results_matrix[unique_count] = (char **)malloc(sizeof(char *) * INFOBOX_FIELD_COUNT); + if (!results_matrix[unique_count]) { + free(seen_urls[unique_count]); + free(all_results[i][j].url); + free(all_results[i][j].title); + free(all_results[i][j].snippet); + continue; + } char *pretty_url = pretty_display_url(display_url); results_matrix[unique_count][0] = strdup(display_url); |
