hw/ppc: Fix missing return on allocation failure
PATCH 1/2 hw/ppc: Fix missing return on allocation failure
Fixes coverity (CID 1642026)
--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/spapr_fadump.c +1 -0
@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region)qemu_log_mask (LOG_GUEST_ERROR ,"FADump: Failed allocating memory (size: %zu) for copying" " reserved memory regions\n" ,FADUMP_CHUNK_SIZE ); +return false; } num_chunks =ceil ((src_len *1.0f ) /FADUMP_CHUNK_SIZE );
Signature · 1 line
2.51.0
PATCH 2/2 hw/ppc: Fix memory leak in get_cpu_state_data()
Fixes coverity (CID 1642024)
--- hw/ppc/spapr_fadump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_fadump.c +1 -1
@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu,static void *get_cpu_state_data (uint64_t *cpu_state_len) {FadumpRegSaveAreaHeader reg_save_hdr; -FadumpRegEntry *reg_entries; + g_autofree FadumpRegEntry *reg_entries;FadumpRegEntry *curr_reg_entry;CPUState *cpu;
Signature · 1 line
2.51.0
Re: [PATCH 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()
Hi Shivang,
Quoted 17 lines · Shivang Upadhyay
Fixes coverity (CID 1642024)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/spapr_fadump.c +0
-0
hw/ppc/spapr_fadump.c static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu, · line 456
Quoted 5 lines
hw/ppc/spapr_fadump.c +1
-1@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu,static void *get_cpu_state_data (uint64_t *cpu_state_len) {FadumpRegSaveAreaHeader reg_save_hdr; -FadumpRegEntry *reg_entries; + g_autofree FadumpRegEntry *reg_entries;
g_autofree pointers have to be NULL-initialized. I don't remember why, likely CPP warnings.
Quoted 3 lines
hw/ppc/spapr_fadump.c +0
-0FadumpRegEntry *curr_reg_entry;CPUState *cpu;
Re: [PATCH 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()
Quoted 15 lines · Philippe Mathieu-Daudé
Hi Shivang,
Quoted 12 lines · Shivang Upadhyay
Fixes coverity (CID 1642024)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/ CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/Reported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>---
hw/ppc/spapr_fadump.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
hw/ppc/spapr_fadump.c static FadumpRegEntry · line 457
Quoted 11 lines
hw/ppc/spapr_fadump.c +1
-1@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu, static void *get_cpu_state_data(uint64_t *cpu_state_len) { FadumpRegSaveAreaHeader reg_save_hdr; - FadumpRegEntry *reg_entries; + g_autofree FadumpRegEntry *reg_entries;
g_autofreepointers have to be NULL-initialized. I don't remember why, likely CPP warnings.
Ah, see for example commit c8f48b120b3:
As mentioned in docs/devel/style.rst "Automatic memory deallocation":
* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory
and for full context, commit 821f2967562 ("docs: document use of automatic cleanup functions in glib").
Re: [PATCH 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé
Hi Shivang,
Quoted 13 lines · Shivang Upadhyay
Fixes coverity (CID 1642024)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/
Reported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>---
hw/ppc/spapr_fadump.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
hw/ppc/spapr_fadump.c static FadumpRegEntry · line 457
Quoted 11 lines
hw/ppc/spapr_fadump.c +1
-1@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu, static void *get_cpu_state_data(uint64_t *cpu_state_len) { FadumpRegSaveAreaHeader reg_save_hdr; - FadumpRegEntry *reg_entries; + g_autofree FadumpRegEntry *reg_entries;
g_autofreepointers have to be NULL-initialized. I don't remember why, likely CPP warnings.Ah, see for example commit
c8f48b120b3:
Quoted 7 lines
As mentioned in
docs/devel/style.rst"Automatic memory deallocation":* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory
and for full context, commit
821f2967562("docs: document use of automatic cleanup functions in glib").
Hi Philippe,
Thanks for fix and explaination.
I'll send out v2 soon.
~Shivang.