Blame SOURCES/0215-libcxl-fox-a-resource-leak-and-a-forward-NULL-check.patch

26ccd9
From 4750c7f50050195bbd427da69037645916a59b24 Mon Sep 17 00:00:00 2001
26ccd9
From: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
Date: Tue, 23 Aug 2022 01:45:26 -0600
26ccd9
Subject: [PATCH 215/217] libcxl: fox a resource leak and a forward NULL check
26ccd9
26ccd9
Static analysis reports a couple of issues in add_cxl_region(). Firstly,
26ccd9
'path' wasn't freed in the success case, only in the error case.
26ccd9
Secondly, the error handling after 'calloc()'ing the region object
26ccd9
erroneously jumped to the error path which tried to free the region object.
26ccd9
26ccd9
Add a new error label to just free 'path' and return for this exit case.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/20220823074527.404435-3-vishal.l.verma@intel.com
26ccd9
Cc: Dan Williams <dan.j.williams@intel.com>
26ccd9
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 cxl/lib/libcxl.c | 4 +++-
26ccd9
 1 file changed, 3 insertions(+), 1 deletion(-)
26ccd9
26ccd9
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
26ccd9
index 021d59f..e8c5d44 100644
26ccd9
--- a/cxl/lib/libcxl.c
26ccd9
+++ b/cxl/lib/libcxl.c
26ccd9
@@ -482,7 +482,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base)
26ccd9
 
26ccd9
 	region = calloc(1, sizeof(*region));
26ccd9
 	if (!region)
26ccd9
-		goto err;
26ccd9
+		goto err_path;
26ccd9
 
26ccd9
 	region->id = id;
26ccd9
 	region->ctx = ctx;
26ccd9
@@ -551,11 +551,13 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base)
26ccd9
 
26ccd9
 	list_add_sorted(&decoder->regions, region, list, region_start_cmp);
26ccd9
 
26ccd9
+	free(path);
26ccd9
 	return region;
26ccd9
 err:
26ccd9
 	free(region->dev_path);
26ccd9
 	free(region->dev_buf);
26ccd9
 	free(region);
26ccd9
+err_path:
26ccd9
 	free(path);
26ccd9
 	return NULL;
26ccd9
 }
26ccd9
-- 
26ccd9
2.27.0
26ccd9