[PATCH 07/15] libtracefs: prevent a memory leak in add_func_str()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Free func_list if strdup() fails.

Fixes a RESSOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx>
---
 src/tracefs-tools.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index 8e7b46d..74cfe91 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -559,8 +559,10 @@ static int add_func_str(struct func_list ***next_func_ptr, const char *func)
 		if (!func_list)
 			return -1;
 		func_list->func = strdup(func);
-		if (!func_list->func)
+		if (!func_list->func) {
+			free(func_list);
 			return -1;
+		}
 		*next_func = func_list;
 		return 0;
 	}
-- 
2.44.0





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux