From 67287701aeca061f9df6c96bbf05df3dc4c5d1a9 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 27 Jul 2022 12:55:20 -0600 Subject: [PATCH] tools/cgxget: 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 --- src/tools/cgxget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cgxget.c b/src/tools/cgxget.c index 787c0e25..0a8cbc56 100644 --- a/src/tools/cgxget.c +++ b/src/tools/cgxget.c @@ -520,7 +520,7 @@ static int get_cv_value(struct control_value * const cv, const char * const cg_n 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) { -- 2.47.2