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

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