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

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