]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Add fclose() calls for error handling
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Tue, 31 Mar 2009 02:18:27 +0000 (11:18 +0900)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 31 Mar 2009 06:03:10 +0000 (11:33 +0530)
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 <oomichi@mxs.nes.nec.co.jp>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
src/api.c
src/config.c
src/tools/cgclassify.c

index 28365b409bbec11f897cd5cd20416b0a2fe80928..d31cf4d544059cdfeca4afba0c30444db193699d 100644 (file)
--- 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,
index b1889851c568e4aa2519dd059c0e4a99bf3efd3a..a93fccee042de7f1bb85184d8fe0494c07936ced 100644 (file)
@@ -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;
        }
 
index c0446087d29ced979ae470aec250238ce9f19db5..79d3477d0936d55c49c49a24180334098db59895 100644 (file)
@@ -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;