]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgsnapshot: add ret value fix in parse_controllers()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 20 Jul 2022 17:00:38 +0000 (11:00 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 20 Jul 2022 17:00:41 +0000 (11:00 -0600)
Fix the unused ret value warning, reported by Coverity:

CID 258275 (#1 of 1): Unused value (UNUSED_VALUE)returned_value:
Assigning value from display_controller_data(controllers, program_name)
to ret here, but that stored value is overwritten before it can be used.

The parse_controllers(), doesn't check for errors in the value returned
by display_controller_data(). The return value might very well contain
an error, that might go unnoticed. Fix it by adding a check for the
return value.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f2f107c8b3ef0f699c0a3f77aeebbcbeb4f1b8b1)

src/tools/cgsnapshot.c

index 0165a469f4bd0be936007f1ea782411978be584e..e20b6cb506c5ee36463555b4a2da14d0582932fa 100644 (file)
@@ -570,6 +570,8 @@ static int parse_controllers(cont_name_t cont_names[CG_CONTROLLER_MAX],
                                (controllers[max])[0] = '\0';
                                ret = display_controller_data(
                                        controllers, program_name);
+                               if (ret)
+                                       goto err;
                        }
 
                        strncpy(controllers[0], controller.name, FILENAME_MAX);
@@ -592,6 +594,7 @@ static int parse_controllers(cont_name_t cont_names[CG_CONTROLLER_MAX],
                        controllers, program_name);
        }
 
+err:
        cgroup_get_controller_end(&handle);
        if (ret != ECGEOF)
                return ret;