]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgget: fix coverity warning about resource leak
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 16 May 2022 21:57:45 +0000 (15:57 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 16 May 2022 21:57:49 +0000 (15:57 -0600)
Fix two resource leaks reported by Coverity tool:

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

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

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

index a0278f9353de2b9100cca7db9e924d795ba4563d..198c793d3df2c31830b48fd9a449d5a252f0d4b9 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -4974,6 +4974,7 @@ int cgroup_read_value_end(void **handle)
 
        fp = (FILE *)*handle;
        fclose(fp);
+       *handle = NULL;
 
        return 0;
 }
index 7abc2d6b5509550c87161094ea375e21f09739ee..009d468c6f52ee83106e1ec5db6b1654a384d435 100644 (file)
@@ -547,6 +547,9 @@ end:
                cv->multiline_value = NULL;
        }
 
+       if ((FILE *)handle)
+               fclose((FILE *)handle);
+
        return ret;
 }
 
@@ -643,9 +646,10 @@ static int fill_empty_controller(struct cgroup * const cg,
                }
        }
 
-       closedir(dir);
-
 out:
+       if (dir)
+               closedir(dir);
+
        pthread_rwlock_unlock(&cg_mount_table_lock);
        return ret;
 }