fix memory leak
cover fix memory leak
From: Gonglei <[email protected]>
Spotted by Coverity.
Gonglei (4):
cpu: fix memory leak
ppc/spapr_drc: fix memory leak
arm/xlnx-zynqmp: fix memory leak
vl.c: fix memory leak
hw/arm/xlnx-zynqmp.c | 4 ++-- hw/ppc/spapr_drc.c | 1 + target-i386/cpu.c | 2 +- vl.c | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.12.4
PATCH 1/4 cpu: fix memory leak
From: Gonglei <[email protected]>
Failing to save or free storage allocated
by "g_strdup(names[0])" leaks it. Actually,
we can pass names[0] directly.
--- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.c +1 -1
@@ -3021,7 +3021,7 @@ static void x86_cpu_register_feature_bit_props(X86CPU *cpu,for (i =1 ; names[i]; i++) {feat2prop (names[i]); -object_property_add_alias (obj, names[i], obj,g_strdup (names[0 ]), +object_property_add_alias (obj, names[i], obj, names[0 ], &error_abort); }
Signature · 1 line
1.7.12.4
PATCH 2/4 ppc/spapr_drc: fix memory leak
In reply to [email protected]From: Gonglei <[email protected]>
fix CID 1311373.
--- hw/ppc/spapr_drc.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/spapr_drc.c +1 -0
@@ -422,6 +422,7 @@ static void realize(DeviceState *d, Error **errp)error_free (err);object_unref (OBJECT (drc)); } +g_free (child_name);DPRINTFN ("drc realize complete" ); }
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/4] ppc/spapr_drc: fix memory leak
Quoting [email protected] (2015-07-09 19:51:28)
Quoted 5 lines
From: Gonglei <[email protected]>
fix CID 1311373.
Signed-off-by Gonglei <[email protected]>
Quoted 21 lines
--- hw/ppc/spapr_drc.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr_drc.c +1
-0@@ -422,6 +422,7 @@ static void realize(DeviceState *d, Error **errp)error_free (err);object_unref (OBJECT (drc)); } +g_free (child_name);DPRINTFN ("drc realize complete" ); }Signature · 1 line
1.7.12.4
PATCH 3/4 arm/xlnx-zynqmp: fix memory leak
In reply to [email protected]From: Gonglei <[email protected]>
fix CID 1311372.
--- hw/arm/xlnx-zynqmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/xlnx-zynqmp.c +2 -2
@@ -144,7 +144,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) }else { s->boot_cpu_ptr = &s->apu_cpu[i]; } - +g_free (name);object_property_set_int (OBJECT (&s->apu_cpu[i]),GIC_BASE_ADDR ,"reset-cbar" , &err);if (err) {
@@ -181,7 +181,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) }else { s->boot_cpu_ptr = &s->rpu_cpu[i]; } - +g_free (name);object_property_set_bool (OBJECT (&s->rpu_cpu[i]), true,"reset-hivecs" , &err);if (err !=NULL ) {
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH 3/4] arm/xlnx-zynqmp: fix memory leak
Quoted 14 lines · On Thu, Jul 9, 2015 at 5:51 PM, <[email protected]> wrote:
From: Gonglei <[email protected]>
fix CID 1311372.
Signed-off-by Gonglei <[email protected]>--- hw/arm/xlnx-zynqmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/arm/xlnx-zynqmp.c +0
-0
hw/arm/xlnx-zynqmp.c static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) · line 147
Quoted 4 lines
hw/arm/xlnx-zynqmp.c +0
-1@@ -144,7 +144,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) }else { s->boot_cpu_ptr = &s->apu_cpu[i]; } -
Thanks,
Please keep this blank line here and below. The g_gree should group with the above code.
Otherwise,
Regards,
Peter
Quoted 18 lines
hw/arm/xlnx-zynqmp.c +2
-2+g_free (name);object_property_set_int (OBJECT (&s->apu_cpu[i]),GIC_BASE_ADDR ,"reset-cbar" , &err);if (err) {@@ -181,7 +181,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) }else { s->boot_cpu_ptr = &s->rpu_cpu[i]; } - +g_free (name);object_property_set_bool (OBJECT (&s->rpu_cpu[i]), true,"reset-hivecs" , &err);if (err !=NULL ) { --1.7.12.4
PATCH 4/4 vl.c: fix memory leak
In reply to [email protected]From: Gonglei <[email protected]>
Failing to save or free storage allocated
by "g_strdup(cmd)" leaks it. Let's use a
variable to storage it.
--- vl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
vl.c +4 -1
@@ -1326,16 +1326,19 @@ static int add_semihosting_arg(void *opaque,static inline void semihosting_arg_fallback (const char *file,const char *cmd) {char *cmd_token; +char *cmd_str;/* argv[0] */ add_semihosting_arg (&semihosting,"arg" , file,NULL ); + cmd_str =g_strdup (cmd);/* split -append and initialize argv[1..n] */ - cmd_token =strtok (g_strdup (cmd)," " ); + cmd_token =strtok (cmd_str," " );while (cmd_token) {add_semihosting_arg (&semihosting,"arg" , cmd_token,NULL ); cmd_token =strtok (NULL ," " ); } +g_free (cmd_str); }/***********************************************************/
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH 4/4] vl.c: fix memory leak
Quoted 27 lines · On 10/07/2015 01:51, [email protected] wrote:
From: Gonglei <[email protected]>
Failing to save or free storage allocated
by "g_strdup(cmd)" leaks it. Let's use a
variable to storage it.Signed-off-by Gonglei <[email protected]>--- vl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)vl.c +2
-0@@ -1326,16 +1326,19 @@ static int add_semihosting_arg(void *opaque,static inline void semihosting_arg_fallback (const char *file,const char *cmd) {char *cmd_token; +char *cmd_str;/* argv[0] */ add_semihosting_arg (&semihosting,"arg" , file,NULL ); + cmd_str =g_strdup (cmd);/* split -append and initialize argv[1..n] */
vl.c static int add_semihosting_arg(void *opaque, · line 1344
Quoted 10 lines
vl.c +2
-1- cmd_token =strtok (g_strdup (cmd)," " ); + cmd_token =strtok (cmd_str," " );while (cmd_token) {add_semihosting_arg (&semihosting,"arg" , cmd_token,NULL ); cmd_token =strtok (NULL ," " ); } +g_free (cmd_str); }/***********************************************************/
I don't think this is correct as there's no leak here. This duplicated string is modified (i.e. split into tokens) and each pointer to the beginning of a token is saved in the global semihosting.argv[] array which is used later in target semihosting code. It shouldn't be freed.
Regards,
Leon
Re: [Qemu-devel] [PATCH 4/4] vl.c: fix memory leak
Quoted 36 lines · Leon Alrae
Quoted 35 lines · On 10/07/2015 01:51, [email protected] wrote:
From: Gonglei <[email protected]>
Failing to save or free storage allocated
by "g_strdup(cmd)" leaks it. Let's use a
variable to storage it.Signed-off-by Gonglei <[email protected]>--- vl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)vl.c +4
-1@@ -1326,16 +1326,19 @@ static int add_semihosting_arg(void *opaque,static inline void semihosting_arg_fallback (const char *file,const char *cmd) {char *cmd_token; +char *cmd_str;/* argv[0] */ add_semihosting_arg (&semihosting,"arg" , file,NULL ); + cmd_str =g_strdup (cmd);/* split -append and initialize argv[1..n] */ - cmd_token =strtok (g_strdup (cmd)," " ); + cmd_token =strtok (cmd_str," " );while (cmd_token) {add_semihosting_arg (&semihosting,"arg" , cmd_token,NULL ); cmd_token =strtok (NULL ," " ); } +g_free (cmd_str); }
Quoted 8 lines
vl.c static int add_semihosting_arg(void *opaque, · line 1344
Quoted 2 lines
vl.c +0
-0/***********************************************************/ I don't think this is correct as there's no leak here. This duplicated string is modified (i.e. split into tokens) and each pointer to the beginning of a token is saved in the global semihosting.argv[] array which is used later in target semihosting code. It shouldn't be freed.
Yep, I look over the logic, and you are right. :)
False positive report. NACK please.
Thanks,
-Gonglei
Quoted 10 lines · On 10/07/2015 02:51, [email protected] wrote:
From: Gonglei <[email protected]>
Spotted by Coverity.
Gonglei (4):
cpu: fix memory leak
ppc/spapr_drc: fix memory leak
arm/xlnx-zynqmp: fix memory leak
vl.c: fix memory leak
Quoted 6 lines
hw/arm/xlnx-zynqmp.c | 4 ++-- hw/ppc/spapr_drc.c | 1 + target-i386/cpu.c | 2 +- vl.c | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-)
Eduardo posted a patch for 1, too.
Paolo