[PATCH] perf arm: Fix memory leak in find_all_arm_spe_pmus()

liujing posted 1 patch 3 weeks, 1 day ago
[PATCH] perf arm: Fix memory leak in find_all_arm_spe_pmus()
Posted by liujing 3 weeks, 1 day ago
From: Liu Jing <liujing@cmss.chinamobile.com>

In find_all_arm_spe_pmus(), if sprintf() fails, the function returns NULL
without freeing the previously allocated arm_spe_pmus array, causing a
memory leak.

Fix it by adding free(arm_spe_pmus) before the return NULL statement.

Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
--- a/tools/perf/arch/arm/util/auxtrace.c
+++ b/tools/perf/arch/arm/util/auxtrace.c
@@ -39,6 +39,7 @@
 		if (ret < 0) {
 			pr_err("sprintf failed\n");
 			*err = -ENOMEM;
+			free(arm_spe_pmus);
 			return NULL;
 		}