]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgsnapshot: in special cases memory/fd is not freed
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 16 Jun 2011 13:08:25 +0000 (15:08 +0200)
committerJan Safranek <jsafrane@redhat.com>
Mon, 20 Jun 2011 08:56:58 +0000 (10:56 +0200)
this patch adds several missing frees in cgsnapshot tool

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

index fe7496d3dddad2504f5b232609e1d77a76458ceb..30e7b6de33e17d54c517ba76d687ec483b0ae80e 100644 (file)
@@ -113,6 +113,10 @@ int load_list(char *filename, struct black_list_type **p_list)
                if ((buf[i] == '#') || (buf[i] == '\0'))
                        continue;
 
+               ret = sscanf(buf, "%s", name);
+               if (ret == 0)
+                       continue;
+
                new = (struct black_list_type *)malloc(sizeof
                        (struct black_list_type));
                if (new == NULL) {
@@ -122,15 +126,12 @@ int load_list(char *filename, struct black_list_type **p_list)
                        goto err;
                }
 
-               ret = sscanf(buf, "%s", 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;
+                       free(new);
                        goto err;
                }
                new->next = NULL;
@@ -145,11 +146,11 @@ int load_list(char *filename, struct black_list_type **p_list)
                }
        }
 
-       fclose(fw);
        *p_list = start;
        return 0;
 
 err:
+       fclose(fw);
        new = start;
        while (new != NULL) {
                end = new->next;