clean up some memory leaks
authorWilliam Douglas <william.douglas@linux.intel.com>
Thu, 7 Apr 2011 17:43:52 +0000 (20:43 +0300)
committerWilliam Douglas <william.douglas@linux.intel.com>
Thu, 7 Apr 2011 17:43:52 +0000 (20:43 +0300)
coredump.c
submit.c

index 6652296..07b2883 100644 (file)
@@ -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);
                }
        }
 
index 338f341..3e58d85 100644 (file)
--- 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);
 }