From dd1602c51180a63d2c75c049d7296c96cc1f51e9 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 31 Mar 2009 11:18:27 +0900 Subject: [PATCH] Add fclose() calls for error handling I reviewed the libcgroup code in the viewpoint of memory-leak and found some lacks of fclose(). This patch adds some fclose() calls for error handling. Signed-off-by: Ken'ichi Ohmichi Signed-off-by: Dhaval Giani --- src/api.c | 7 +++++-- src/config.c | 1 + src/tools/cgclassify.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api.c b/src/api.c index 28365b40..d31cf4d5 100644 --- a/src/api.c +++ b/src/api.c @@ -696,14 +696,17 @@ static int cg_test_mounted_fs() temp_ent = (struct mntent *) malloc(sizeof(struct mntent)); if (!temp_ent) { /* We just fail at the moment. */ + fclose(proc_mount); return 0; } ent = getmntent_r(proc_mount, temp_ent, mntent_buff, sizeof(mntent_buff)); - if (!ent) - return 0; + if (!ent) { + ret = 0; + goto done; + } while (strcmp(ent->mnt_type, "cgroup") !=0) { ent = getmntent_r(proc_mount, temp_ent, mntent_buff, diff --git a/src/config.c b/src/config.c index b1889851..a93fccee 100644 --- a/src/config.c +++ b/src/config.c @@ -469,6 +469,7 @@ int cgroup_config_load_config(const char *pathname) if (yyparse() != 0) { cgroup_dbg("Failed to parse file %s\n", pathname); + fclose(yyin); return ECGROUPPARSEFAIL; } diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c index c0446087..79d3477d 100644 --- a/src/tools/cgclassify.c +++ b/src/tools/cgclassify.c @@ -57,9 +57,11 @@ int euid_of_pid(pid_t pid) (int *)&euid, (int *)&suid, (int *)&fsuid); cgroup_dbg("Scanned proc values are %d %d %d %d\n", ruid, euid, suid, fsuid); + fclose(fp); return euid; } } + fclose(fp); /* If we are here, we could not find euid. Return error. */ return -1; -- 2.47.2