From b39f7cc778903e9cda8aa46d170b9efe80efda89 Mon Sep 17 00:00:00 2001 From: Jim Fehlig Date: Tue, 7 Jan 2020 11:41:11 -0700 Subject: [PATCH 11/19] util: Fix potential memory leak From coverity scan vhostmd-1.1/vhostmd/util.c:415:14: warning: Potential leak of memory pointed to by 'cp' return(NULL); Signed-off-by: Jim Fehlig --- vhostmd/util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vhostmd/util.c b/vhostmd/util.c index 1f9545b..599c5c7 100644 --- a/vhostmd/util.c +++ b/vhostmd/util.c @@ -415,7 +415,7 @@ char *vu_str_replace(const char *haystack, const char *origstr, const char *news dest = malloc(strlen(haystack) - (origlen * cnt) + (newlen * cnt) + 1); if (dest == NULL) { - return(NULL); + goto out; } *dest = '\0'; @@ -428,6 +428,8 @@ char *vu_str_replace(const char *haystack, const char *origstr, const char *news cp = p + origlen; } strcat(dest, cp); + +out: free(tempstr); return dest; -- 2.32.0