* [PATCH for-5.2] hw/mips/boston.c: Fix memory leak in boston_fdt_filter() error-handling paths
@ 2020-11-06 17:58 Peter Maydell
2020-11-06 18:38 ` Philippe Mathieu-Daudé
2020-11-08 23:13 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2020-11-06 17:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Aleksandar Rikalo, Philippe Mathieu-Daudé, Paul Burton
Coverity points out that the error-handling paths in the
boston_fdt_filter() function don't free the fdt that was allocated.
Fix the leak by using g_autofree.
Fixes: Coverity CID 1432275
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/mips/boston.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 3356d7a6814..3d40867dc4c 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -349,11 +349,9 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
MachineState *machine = s->mach;
const char *cmdline;
int err;
- void *fdt;
- size_t fdt_sz, ram_low_sz, ram_high_sz;
-
- fdt_sz = fdt_totalsize(fdt_orig) * 2;
- fdt = g_malloc0(fdt_sz);
+ size_t ram_low_sz, ram_high_sz;
+ size_t fdt_sz = fdt_totalsize(fdt_orig) * 2;
+ g_autofree void *fdt = g_malloc0(fdt_sz);
err = fdt_open_into(fdt_orig, fdt, fdt_sz);
if (err) {
@@ -380,7 +378,7 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
s->fdt_base = *load_addr;
- return fdt;
+ return g_steal_pointer(&fdt);
}
static const void *boston_kernel_filter(void *opaque, const void *kernel,
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH for-5.2] hw/mips/boston.c: Fix memory leak in boston_fdt_filter() error-handling paths
2020-11-06 17:58 [PATCH for-5.2] hw/mips/boston.c: Fix memory leak in boston_fdt_filter() error-handling paths Peter Maydell
@ 2020-11-06 18:38 ` Philippe Mathieu-Daudé
2020-11-08 23:13 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-11-06 18:38 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Aleksandar Rikalo, Paul Burton
On 11/6/20 6:58 PM, Peter Maydell wrote:
> Coverity points out that the error-handling paths in the
> boston_fdt_filter() function don't free the fdt that was allocated.
> Fix the leak by using g_autofree.
>
> Fixes: Coverity CID 1432275
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/mips/boston.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH for-5.2] hw/mips/boston.c: Fix memory leak in boston_fdt_filter() error-handling paths
2020-11-06 17:58 [PATCH for-5.2] hw/mips/boston.c: Fix memory leak in boston_fdt_filter() error-handling paths Peter Maydell
2020-11-06 18:38 ` Philippe Mathieu-Daudé
@ 2020-11-08 23:13 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-11-08 23:13 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Aleksandar Rikalo, Paul Burton
On 11/6/20 6:58 PM, Peter Maydell wrote:
> Coverity points out that the error-handling paths in the
> boston_fdt_filter() function don't free the fdt that was allocated.
> Fix the leak by using g_autofree.
>
> Fixes: Coverity CID 1432275
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/mips/boston.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
Thanks, applied to mips-fixes.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-08 23:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-06 17:58 [PATCH for-5.2] hw/mips/boston.c: Fix memory leak in boston_fdt_filter() error-handling paths Peter Maydell
2020-11-06 18:38 ` Philippe Mathieu-Daudé
2020-11-08 23:13 ` 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).