From b029a915a2a1eb97510331092cef381b1dcf1d3d Mon Sep 17 00:00:00 2001 From: William Douglas Date: Thu, 7 Apr 2011 20:43:52 +0300 Subject: [PATCH] clean up some memory leaks --- coredump.c | 14 ++++++++------ submit.c | 27 +++++++++++++++------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/coredump.c b/coredump.c index 6652296..07b2883 100644 --- a/coredump.c +++ b/coredump.c @@ -73,18 +73,20 @@ char *get_build(void) { if (getline(&line, &dummy, file) <= 0) break; if (strstr(line, "BUILD") != NULL) { - char *c; - - c = strchr(line, '\n'); - if (c) *c = 0; + char *c, *build; c = strstr(line, "BUILD"); c += 7; - c = strdup(c); + build = strdup(c); + + c = strchr(build, '\n'); + if (c) *c = 0; free(line); fclose(file); - return c; + return build; + } else { + free(line); } } diff --git a/submit.c b/submit.c index 338f341..3e58d85 100644 --- a/submit.c +++ b/submit.c @@ -152,7 +152,7 @@ void unlink_detail_file(void) static void print_queue(void) { - struct oops *oops; + struct oops *oops, *next; struct oops *queue; int count = 0; @@ -161,8 +161,6 @@ static void print_queue(void) barrier(); oops = queue; while (oops) { - struct oops *next; - fprintf(stderr, "+ Submit text is:\n---[start of oops]---\n%s\n---[end of oops]---\n", oops->text); next = oops->next; free(oops->application); @@ -172,7 +170,6 @@ static void print_queue(void) oops = next; count++; } - } static void write_logfile(int count, char *wsubmit_url) @@ -216,7 +213,6 @@ void submit_queue_with_url(struct oops *queue, char *wsubmit_url) while (oops) { struct curl_httppost *post = NULL; struct curl_httppost *last = NULL; - struct oops *next; unsigned int sum; int i; @@ -273,12 +269,7 @@ void submit_queue_with_url(struct oops *queue, char *wsubmit_url) count++; dup: - next = oops->next; - free(oops->application); - free(oops->text); - free(oops->filename); - free(oops); - oops = next; + oops = oops->next; } curl_easy_cleanup(handle); @@ -299,7 +290,7 @@ void submit_queue_with_url(struct oops *queue, char *wsubmit_url) void submit_queue(void) { int i; - struct oops *queue; + struct oops *queue, *oops, *next; CURL *handle; memset(result_url, 0, 4096); @@ -325,6 +316,18 @@ void submit_queue(void) } } + + + oops = queue; + while (oops) { + next = oops->next; + free(oops->application); + free(oops->text); + free(oops->filename); + free(oops); + oops = next; + } + curl_easy_cleanup(handle); } -- 2.7.4