]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
lssubsys: Fixed file descriptor leak on error enumerating controllers.
authorJan Safranek <jsafrane@redhat.com>
Wed, 24 Aug 2011 09:41:26 +0000 (11:41 +0200)
committerJan Safranek <jsafrane@redhat.com>
Wed, 14 Sep 2011 11:24:33 +0000 (13:24 +0200)
Close the iterator when cgroup_get_all_controller_next fails. I've
rewritten the loop to have one error check for both
cgroup_get_all_controller_begin and cgroup_get_all_controller_end.

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
src/tools/lssubsys.c

index 28ef4560ecac7d71dc1221d5b0b904e56d066413..d64f6deb4548676655df8a18307cd819a231b78b 100644 (file)
@@ -167,8 +167,7 @@ static int cgroup_list_all_controllers(const char *tname,
        int is_on_list = 0;
 
        ret = cgroup_get_all_controller_begin(&handle, &info);
-
-       while (ret != ECGEOF) {
+       while (ret == 0) {
                if (info.hierarchy == 0) {
                        /* the controller is not attached to any hierrachy */
                        if (flags & FL_ALL)
@@ -207,15 +206,17 @@ static int cgroup_list_all_controllers(const char *tname,
                }
 
                ret = cgroup_get_all_controller_next(&handle, &info);
-               if (ret && ret != ECGEOF) {
-                       fprintf(stderr,
-                               "cgroup_get_controller_next failed (%s)\n",
-                               cgroup_strerror(ret));
-                       return ret;
-               }
+       }
+       cgroup_get_all_controller_end(&handle);
+       if (ret == ECGEOF)
+               ret = 0;
+       if (ret) {
+               fprintf(stderr,
+                       "cgroup_get_controller_begin/next failed (%s)\n",
+                       cgroup_strerror(ret));
+               return ret;
        }
 
-       ret = cgroup_get_all_controller_end(&handle);
 
        for (j = 0; j < counter; j++)
                ret = print_all_controllers_in_hierarchy(tname,