From: Kamalesh Babulal Date: Wed, 27 Jul 2022 18:49:57 +0000 (-0600) Subject: tools/cgget: fix resource leak in get_cv_value() X-Git-Tag: v2.0.3~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5031f8b5472a41c53f517188dff7adfa1b04f2c;p=thirdparty%2Flibcgroup.git tools/cgget: fix resource leak in get_cv_value() Fix a resource leak, reported by the Coverity tool: CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK)8. leaked_storage: Variable handle going out of scope leaks the storage it points to. In get_cv_value(), 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 Signed-off-by: Tom Hromatka (cherry picked from commit d8bf0b38a75ed06520d05d130c0c92234df8665f) --- diff --git a/src/tools/cgget.c b/src/tools/cgget.c index f80926ba..42949808 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -496,7 +496,7 @@ static int get_cv_value(struct control_value * const cv, strncpy(cv->value, tmp_line, CG_CONTROL_VALUE_MAX - 1); cv->multiline_value = strdup(cv->value); if (cv->multiline_value == NULL) - goto end; + goto read_end; while((ret = cgroup_read_value_next(&handle, tmp_line, LL_MAX)) == 0) { if (ret == 0) {