From: Kamalesh Babulal Date: Wed, 25 May 2022 13:50:07 +0000 (-0600) Subject: tools/cgget: fix coverity warning about double free X-Git-Tag: v2.0.3~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa6010f03b4f85303e167d5230e6aadca7e7645f;p=thirdparty%2Flibcgroup.git tools/cgget: fix coverity warning about double free Fix double free warning, reported by Coverity tool: CID 258297 (#1 of 1): Double free (USE_AFTER_FREE). double_free: Calling closedir frees pointer dir which has already been freed. As per the man page, the closedir(), closes the directory stream associated with the dirp, but is ambiguous about if dirp is set to NULL or not. Coverity answers that with the above report, that dirp is not NULL and hence the double free. Fixes: fea1ab8b45d7 ("tools/cgget: fix coverity warning about resource leak") Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 703bbb8554ce882eb461e16c389d20a356f095de) --- diff --git a/src/tools/cgget.c b/src/tools/cgget.c index 15db093f..f27a0cda 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -608,10 +608,8 @@ static int fill_empty_controller(struct cgroup * const cg, continue; ret = cgroup_fill_cgc(ctrl_dir, cg, cgc, i); - if (ret == ECGFAIL) { - closedir(dir); + if (ret == ECGFAIL) goto out; - } if (cgc->index > 0) { cgc->values[cgc->index - 1]->dirty = false;