diff mbox series

[ndctl,2/3] libcxl: fox a resource leak and a forward NULL check

Message ID 20220823072106.398076-3-vishal.l.verma@intel.com
State Superseded
Headers show
Series cxl: static analysis fixes | expand

Commit Message

Verma, Vishal L Aug. 23, 2022, 7:21 a.m. UTC
Static analysis reports a couple of issues in add_cxl_region(). Firstly,
'path' wasn't freed in the success case, only in the error case.
Secondly, the error handling after 'calloc()'ing the region object
erroneously jumped to the error path which tried to free the region object,
instead of directly returning NULL.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 cxl/lib/libcxl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 021d59f..9945fd1 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -482,7 +482,7 @@  static void *add_cxl_region(void *parent, int id, const char *cxlregion_base)
 
 	region = calloc(1, sizeof(*region));
 	if (!region)
-		goto err;
+		return NULL;
 
 	region->id = id;
 	region->ctx = ctx;
@@ -551,6 +551,7 @@  static void *add_cxl_region(void *parent, int id, const char *cxlregion_base)
 
 	list_add_sorted(&decoder->regions, region, list, region_start_cmp);
 
+	free(path);
 	return region;
 err:
 	free(region->dev_path);