]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgsnapshot: fix return value checks
authorIvana Hutarova Varekova <varekova@redhat.com>
Tue, 7 Jun 2011 11:19:54 +0000 (13:19 +0200)
committerJan Safranek <jsafrane@redhat.com>
Tue, 7 Jun 2011 13:14:22 +0000 (15:14 +0200)
fix return value checks in load_list functions

Changelog:
* thanks jsafrane free proper list structure properly

Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
src/tools/cgsnapshot.c

index 0ff74352e1684f54cc3bef7ae91e81016963bc1b..fe7496d3dddad2504f5b232609e1d77a76458ceb 100644 (file)
@@ -101,7 +101,7 @@ int load_list(char *filename, struct black_list_type **p_list)
                return 1;
        }
 
-       /* go through the all configuration file and search the line */
+       /* go through the configuration file and search the line */
        while (fgets(buf, FILENAME_MAX, fw) != NULL) {
                buf[FILENAME_MAX-1] = '\0';
                i = 0;
@@ -118,13 +118,21 @@ int load_list(char *filename, struct black_list_type **p_list)
                if (new == NULL) {
                        fprintf(stderr, "ERROR: Memory allocation problem "
                                "(%s)\n", strerror(errno));
-                       *p_list = NULL;
-                       return 1;
+                       ret = 1;
+                       goto err;
                }
 
                ret = sscanf(buf, "%s", name);
-               new->name = strdup(name);
+               if (ret == 0)
+                       continue;
 
+               new->name = strdup(name);
+               if (new->name == NULL) {
+                       fprintf(stderr, "ERROR: Memory allocation problem "
+                               "(%s)\n", strerror(errno));
+                       ret = 1;
+                       goto err;
+               }
                new->next = NULL;
 
                /* update the variables list */
@@ -140,6 +148,17 @@ int load_list(char *filename, struct black_list_type **p_list)
        fclose(fw);
        *p_list = start;
        return 0;
+
+err:
+       new = start;
+       while (new != NULL) {
+               end = new->next;
+               free(new->name);
+               free(new);
+               new = end;
+       }
+       *p_list = NULL;
+       return ret;
 }
 
 /* free list structure */