]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgxget: fix a resource leak get_cv_value()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 8 Jul 2022 16:50:00 +0000 (10:50 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 8 Jul 2022 16:50:07 +0000 (10:50 -0600)
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.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgxget.c

index 9cc75d3247e16b48baa20da9d17f00be62bc1b2e..418b749620e8cbf50df2692cd6b5f1e647504201 100644 (file)
@@ -560,7 +560,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");