From: Kamalesh Babulal Date: Mon, 11 Jul 2022 19:41:16 +0000 (-0600) Subject: tools/cgget: fix a resource leak get_cv_value() X-Git-Tag: v2.0.3~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80452cd88bfa6118df20b81b90a98d3d46dd0190;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 (cherry picked from commit aeded1e4176978d9705dbc5f9d9609ebf843b189) --- diff --git a/src/tools/cgget.c b/src/tools/cgget.c index f27a0cda..714db104 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -509,7 +509,7 @@ static int get_cv_value(struct control_value * const cv, 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");