From: Kamalesh Babulal Date: Mon, 16 May 2022 21:57:45 +0000 (-0600) Subject: tools/cgget: fix coverity warning about resource leak X-Git-Tag: v3.0~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fea1ab8b45d7bbe708c9fd4e66b4d639fa7aa984;p=thirdparty%2Flibcgroup.git tools/cgget: fix coverity warning about resource leak 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 Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index a0278f93..198c793d 100644 --- 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; } diff --git a/src/tools/cgget.c b/src/tools/cgget.c index 7abc2d6b..009d468c 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -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; }