Static analysis reports there can be a memory leak in to_csv as an exit
path returns from the function before freeing 'csv'. Since this is the
only errpr path exit point after the allocation, just free() before
returning.
Fixes: 3d6cd829ec08 ("cxl/region: Use cxl_filter_walk() to gather create-region
targets")
Cc: Dan Williams <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
---
cxl/region.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cxl/region.c b/cxl/region.c
index bb3a10a..9a81113 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -146,8 +146,10 @@ static const char *to_csv(int *count, const char **strings)
return NULL;
for (i = 0; i < *count; i++) {
list = strdup(strings[i]);
- if (!list)
+ if (!list) {
+ free(csv);
return NULL;
+ }
for (arg = strtok_r(list, which_sep(list), &save); arg;
arg = strtok_r(NULL, which_sep(list), &save)) {
--
2.39.0