From: Kamalesh Babulal Date: Mon, 11 Jul 2022 19:40:08 +0000 (-0600) Subject: tools/cgget: fix a resource leak get_cv_value() X-Git-Tag: v3.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeded1e4176978d9705dbc5f9d9609ebf843b189;p=thirdparty%2Flibcgroup.git tools/cgget: fix a resource leak get_cv_value() Fix a resource leak in get_cv_value(), reported by Coverity tool: CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK). leaked_storage: Variable handle going out of scope leaks the storage it points to. failure on the realloc(), doesn't free the *handle. Fix it by using the goto read_end(), that does the job of freeing the handle. Suggested-by: Tom Hromatka Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgget.c b/src/tools/cgget.c index 5c3d3020..ea6a5701 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -506,7 +506,7 @@ static int get_cv_value(struct control_value * const cv, const char * const cg_n tmp = realloc(cv->multiline_value, sizeof(char) * (strlen(cv->multiline_value) + strlen(tmp_line) + 3)); if (tmp == NULL) - goto end; + goto read_end; cv->multiline_value = tmp; strcat(cv->multiline_value, "\n\t");