[PATCH] opal: Fix a few memory leaks on asprint allocated buffers

Colin King colin.king at canonical.com
Wed Sep 22 09:50:16 UTC 2021


From: Colin Ian King <colin.king at canonical.com>

There are a few paths where asprintf allocated buffers are not
being free'd. Fix the leaks.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/opal/mem_info.c | 4 ++++
 src/opal/mtd_info.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/opal/mem_info.c b/src/opal/mem_info.c
index 03b04762..a5291e28 100644
--- a/src/opal/mem_info.c
+++ b/src/opal/mem_info.c
@@ -222,6 +222,7 @@ static int process_dimm(
 				}
 			}
 
+			free(my_path);
 			free(my_buffer);
 			free(namelist[i]);
 		}
@@ -308,6 +309,7 @@ static int process_mba(
 			if (process_dimm(fw, "dimm", my_path)) {
 				failures++;
 			}
+			free(my_path);
 			free(my_buffer);
 			free(namelist[i]);
 		}
@@ -363,6 +365,7 @@ static int get_linux_mem_devices(fwts_framework *fw)
 
 		dirent = namelist[i];
 
+		mem_buffer = NULL;
 		if (dirent->d_name[0] == '.' ||
 			asprintf(&mem_buffer,
 				"%s",
@@ -395,6 +398,7 @@ static int get_linux_mem_devices(fwts_framework *fw)
 			if (process_mba(fw, "mba", mba_path)) {
 				failures++;
 			}
+			free(mba_path);
 			free(mem_buffer);
 			free(namelist[i]);
 		}
diff --git a/src/opal/mtd_info.c b/src/opal/mtd_info.c
index 209b2566..4a00fc46 100644
--- a/src/opal/mtd_info.c
+++ b/src/opal/mtd_info.c
@@ -315,8 +315,8 @@ static int mtd_info_test1(fwts_framework *fw)
 					}
 					fwts_log_nl(fw);
 				}
-				free(mtd_device_path);
 			}
+			free(mtd_device_path);
 		}
 
 		free(namelist[i]);
-- 
2.32.0




More information about the fwts-devel mailing list