* [Qemu-devel] [PATCH] hw/arm/armsse: Fix memory leak in error-exit path
@ 2019-02-15 11:37 Peter Maydell
2019-02-15 20:21 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2019-02-15 11:37 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: patches
Coverity points out (CID 1398632, CID 1398650) that we
leak a couple of allocated strings in the error-exit
code path for setting up the MHUs in the ARMSSE.
Fix this bug by moving the allocate-and-free of each
string to be closer to the use, so we do the free before
doing the error-exit check.
Fixes: f8574705f62b38a ("hw/arm/armsse: Add unimplemented-device stubs for MHUs")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/arm/armsse.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
index 9a8c49547db..d0207dbabc7 100644
--- a/hw/arm/armsse.c
+++ b/hw/arm/armsse.c
@@ -762,26 +762,28 @@ static void armsse_realize(DeviceState *dev, Error **errp)
if (info->has_mhus) {
for (i = 0; i < ARRAY_SIZE(s->mhu); i++) {
- char *name = g_strdup_printf("MHU%d", i);
- char *port = g_strdup_printf("port[%d]", i + 3);
+ char *name;
+ char *port;
+ name = g_strdup_printf("MHU%d", i);
qdev_prop_set_string(DEVICE(&s->mhu[i]), "name", name);
qdev_prop_set_uint64(DEVICE(&s->mhu[i]), "size", 0x1000);
object_property_set_bool(OBJECT(&s->mhu[i]), true,
"realized", &err);
+ g_free(name);
if (err) {
error_propagate(errp, err);
return;
}
+ port = g_strdup_printf("port[%d]", i + 3);
mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mhu[i]), 0);
object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr),
port, &err);
+ g_free(port);
if (err) {
error_propagate(errp, err);
return;
}
- g_free(name);
- g_free(port);
}
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/arm/armsse: Fix memory leak in error-exit path
2019-02-15 11:37 [Qemu-devel] [PATCH] hw/arm/armsse: Fix memory leak in error-exit path Peter Maydell
@ 2019-02-15 20:21 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-15 20:21 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel; +Cc: patches
On 2/15/19 12:37 PM, Peter Maydell wrote:
> Coverity points out (CID 1398632, CID 1398650) that we
> leak a couple of allocated strings in the error-exit
> code path for setting up the MHUs in the ARMSSE.
> Fix this bug by moving the allocate-and-free of each
> string to be closer to the use, so we do the free before
> doing the error-exit check.
>
> Fixes: f8574705f62b38a ("hw/arm/armsse: Add unimplemented-device stubs for MHUs")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> hw/arm/armsse.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
> index 9a8c49547db..d0207dbabc7 100644
> --- a/hw/arm/armsse.c
> +++ b/hw/arm/armsse.c
> @@ -762,26 +762,28 @@ static void armsse_realize(DeviceState *dev, Error **errp)
>
> if (info->has_mhus) {
> for (i = 0; i < ARRAY_SIZE(s->mhu); i++) {
> - char *name = g_strdup_printf("MHU%d", i);
> - char *port = g_strdup_printf("port[%d]", i + 3);
> + char *name;
> + char *port;
>
> + name = g_strdup_printf("MHU%d", i);
> qdev_prop_set_string(DEVICE(&s->mhu[i]), "name", name);
> qdev_prop_set_uint64(DEVICE(&s->mhu[i]), "size", 0x1000);
> object_property_set_bool(OBJECT(&s->mhu[i]), true,
> "realized", &err);
> + g_free(name);
> if (err) {
> error_propagate(errp, err);
> return;
> }
> + port = g_strdup_printf("port[%d]", i + 3);
> mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mhu[i]), 0);
> object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr),
> port, &err);
> + g_free(port);
> if (err) {
> error_propagate(errp, err);
> return;
> }
> - g_free(name);
> - g_free(port);
> }
> }
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-15 20:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-15 11:37 [Qemu-devel] [PATCH] hw/arm/armsse: Fix memory leak in error-exit path Peter Maydell
2019-02-15 20:21 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).