From: Ivana Hutarova Varekova Date: Thu, 16 Jun 2011 13:08:25 +0000 (+0200) Subject: cgsnapshot: in special cases memory/fd is not freed X-Git-Tag: v0.38~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc4845c2eece7a6ab94fbdfc57ab44e4d91ac19e;p=thirdparty%2Flibcgroup.git cgsnapshot: in special cases memory/fd is not freed this patch adds several missing frees in cgsnapshot tool Signed-off-by: Ivana Hutarova Varekova Signed-off-by: Jan Safranek --- diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c index fe7496d3..30e7b6de 100644 --- a/src/tools/cgsnapshot.c +++ b/src/tools/cgsnapshot.c @@ -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;