]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
abstraction-cpu: fix resource leak in read_setting()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 20 Jul 2022 17:06:02 +0000 (11:06 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 20 Jul 2022 17:06:06 +0000 (11:06 -0600)
Fix a resource leak, reported by Coverity tool:

CID 258274 (#1 of 1): Resource leak (RESOURCE_LEAK)6. leaked_storage:
Variable handle going out of scope leaks the storage it points to

In read_setting(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/abstraction-cpu.c

index a7ed6843d3c879be18dd3f4423371a87a3e05757..5a56bc07fe51ebde4570d02b615f7733537e7cf9 100644 (file)
@@ -40,10 +40,8 @@ static int read_setting(const char * const cgroup_name, const char * const contr
                goto end;
 
        *value = strdup(tmp_line);
-       if ((*value) == NULL) {
+       if ((*value) == NULL)
                ret = ECGOTHER;
-               goto end;
-       }
 
 read_end:
        cgroup_read_value_end(&handle);