fix: null checks after some malloc allocations
This commit is contained in:
@@ -118,6 +118,12 @@ int images_handler(UrlParams *params) {
|
|||||||
int max_images = (nodes < 32) ? nodes : 32;
|
int max_images = (nodes < 32) ? nodes : 32;
|
||||||
image_matrix = malloc(sizeof(char **) * max_images);
|
image_matrix = malloc(sizeof(char **) * max_images);
|
||||||
inner_counts = malloc(sizeof(int) * 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++) {
|
for (int i = 0; i < nodes; i++) {
|
||||||
if (image_count >= 32)
|
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] = malloc(sizeof(char *) * 4);
|
||||||
image_matrix[image_count][0] =
|
image_matrix[image_count][0] =
|
||||||
proxy_url ? strdup(proxy_url) : strdup((char *)iurl);
|
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][1] = strdup(title ? (char *)title : "Image");
|
||||||
image_matrix[image_count][2] = strdup(rurl ? (char *)rurl : "#");
|
image_matrix[image_count][2] = strdup(rurl ? (char *)rurl : "#");
|
||||||
image_matrix[image_count][3] =
|
image_matrix[image_count][3] =
|
||||||
|
|||||||
@@ -266,6 +266,18 @@ int results_handler(UrlParams *params) {
|
|||||||
char ***results_matrix = (char ***)malloc(sizeof(char **) * total_results);
|
char ***results_matrix = (char ***)malloc(sizeof(char **) * total_results);
|
||||||
int *results_inner_counts = (int *)malloc(sizeof(int) * total_results);
|
int *results_inner_counts = (int *)malloc(sizeof(int) * total_results);
|
||||||
char **seen_urls = (char **)malloc(sizeof(char *) * 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;
|
int unique_count = 0;
|
||||||
|
|
||||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
@@ -288,8 +300,21 @@ int results_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
seen_urls[unique_count] = strdup(display_url);
|
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] =
|
results_matrix[unique_count] =
|
||||||
(char **)malloc(sizeof(char *) * INFOBOX_FIELD_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);
|
char *pretty_url = pretty_display_url(display_url);
|
||||||
|
|
||||||
results_matrix[unique_count][0] = strdup(display_url);
|
results_matrix[unique_count][0] = strdup(display_url);
|
||||||
|
|||||||
Reference in New Issue
Block a user