From 7a0c7dcadf7c0422afa93febd5ca345a79869452 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Mon, 29 Nov 2021 16:11:34 +0300 Subject: [PATCH] dm: fix memory leakage issue in acrn_parse_cpu_affinity there is memory leakage in this function, where memory pointed by 'cp'. Tracked-On: #6919 Signed-off-by: Yonghua Huang --- devicemodel/core/vmmapi.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index aa02e7fcf..e24747642 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -99,11 +99,11 @@ static void add_one_pcpu(int pcpu_id) */ int acrn_parse_cpu_affinity(char *opt) { - char *str, *cp; + char *str, *cp, *cp_opt; int pcpu_id; int pcpu_start, pcpu_end; - cp = strdup(opt); + cp_opt = cp = strdup(opt); if (!cp) { pr_err("%s: strdup returns NULL\n", __func__); return -1; @@ -126,7 +126,7 @@ int acrn_parse_cpu_affinity(char *opt) /* parse the entry before ',' */ if (dm_strtoi(str, NULL, 10, &pcpu_id)) { - return -1; + goto err; } add_one_pcpu(pcpu_id); } @@ -136,11 +136,11 @@ int acrn_parse_cpu_affinity(char *opt) /* parse the entry before and after '-' respectively */ if (dm_strtoi(str, NULL, 10, &pcpu_start) || dm_strtoi(cp, NULL, 10, &pcpu_end)) { - return -1; + goto err; } if (pcpu_end <= pcpu_start) { - return -1; + goto err; } for (; pcpu_start <= pcpu_end; pcpu_start++) { @@ -153,7 +153,12 @@ int acrn_parse_cpu_affinity(char *opt) } } + free(cp_opt); return 0; + +err: + free(cp_opt); + return -1; } uint64_t vm_get_cpu_affinity_dm(void)