hw/ppc/pegasos: Fix memory leak
PATCH 1/1 hw/ppc/pegasos: Fix memory leak
Commit 9099b430a4 introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.
Resolves: Coverity CID 1642027
--- hw/ppc/pegasos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/pegasos.c +2 -1
@@ -847,7 +847,7 @@ static struct {static void add_pci_device (PCIBus *bus,PCIDevice *d,void *opaque) {FDTInfo *fi = opaque; -GString *node =g_string_new (NULL ); +GString *node;uint32_t cells[(PCI_NUM_REGIONS +1 ) *5 ];int i, j;const char *name =NULL ;
@@ -871,6 +871,7 @@ static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque)break ; } } + node =g_string_new (NULL );g_string_printf (node,"%s/%s@%x" , fi->path, (name ?: pn),PCI_SLOT (d->devfn));if (PCI_FUNC (d->devfn)) {
Signature · 1 line
2.41.3
Quoted 8 lines · BALATON Zoltan
Commit
9099b430a4introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.Fixes 9099b430a4 (hw/ppc/pegasos2: Change device tree generation)Resolves: Coverity CID 1642027
Signed-off-by BALATON Zoltan <[email protected]>---
thanks
-- PMM
Hi Balaton,
Thanks for taking care of this ...
Quoted 3 lines · BALATON Zoltan
Commit
9099b430a4introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.
I think we also want to mention:
Quoted 12 lines
Fixes 9099b430a4 (hw/ppc/pegasos2: Change device tree generation)Resolves: Coverity CID 1642027
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/pegasos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/ppc/pegasos.c +0
-0
hw/ppc/pegasos.c static struct { · line 850
Quoted 5 lines
hw/ppc/pegasos.c +1
-1@@ -847,7 +847,7 @@ static struct {static void add_pci_device (PCIBus *bus,PCIDevice *d,void *opaque) {FDTInfo *fi = opaque; -GString *node =g_string_new (NULL ); +GString *node;
Curious to know if there were any technical reasons for not using g_autoptr which Peter initially suggested ?
Anyways, it fixes the leak, so
Quoted 11 lines
hw/ppc/pegasos.c +1
-0uint32_t cells[(PCI_NUM_REGIONS +1 ) *5 ];int i, j;const char *name =NULL ;@@ -871,6 +871,7 @@ static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque)break ; } } + node =g_string_new (NULL );g_string_printf (node,"%s/%s@%x" , fi->path, (name ?: pn),PCI_SLOT (d->devfn));if (PCI_FUNC (d->devfn)) {
Quoted 5 lines · Harsh Prateek Bora
Hi Balaton,
Thanks for taking care of this ...
Quoted 8 lines
Quoted 3 lines · BALATON Zoltan
Commit
9099b430a4introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.I think we also want to mention:
Reported-by Peter Maydell <[email protected]>
You can if you like, but it's not essential -- I just forward the info from the coverity reports.
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Harsh Prateek Bora
Hi Balaton,
Thanks for taking care of this ...
Quoted 3 lines · BALATON Zoltan
Commit
9099b430a4introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.
Quoted 6 lines
Quoted 3 lines
I think we also want to mention:
Reported-by Peter Maydell <[email protected]>You can if you like, but it's not essential -- I just forward the info from the coverity reports.
Sure, thanks Peter.
I think now that I mentioned it, b4 am will pick it anyway.
regards,
Harsh
Quoted 2 lines
-- PMM
Quoted 4 lines · Harsh Prateek Bora
Hi Balaton,
Thanks for taking care of this ...
Quoted 8 lines
Quoted 3 lines · BALATON Zoltan
Commit
9099b430a4introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.I think we also want to mention:
Reported-by Peter Maydell <[email protected]>
You can add it on merge.
Quoted 7 lines
Quoted 7 lines
Fixes 9099b430a4 (hw/ppc/pegasos2: Change device tree generation)Resolves: Coverity CID 1642027
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/pegasos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 12 lines
hw/ppc/pegasos.c static struct { · line 850
Quoted 10 lines
hw/ppc/pegasos.c +1
-1@@ -847,7 +847,7 @@ static struct {static void add_pci_device (PCIBus *bus,PCIDevice *d,void *opaque) {FDTInfo *fi = opaque; -GString *node =g_string_new (NULL ); +GString *node;Curious to know if there were any technical reasons for not using
g_autoptrwhich Peter initially suggested ?
Just thought it's simpler and more straight forward this way and saves a bit of unnecessary complication. We don't even allocate the string now when we exit, with g_autoptr it might do some additional operations unnecessarily. As this function otherwise does not have multiple exit points just one free at the end works.
Quoted 3 lines
Anyways, it fixes the leak, so
Reviewed-by Harsh Prateek Bora <[email protected]>
Thanks,
BALATON Zoltan
Quoted 15 lines
Quoted 13 lines
hw/ppc/pegasos.c +1
-0uint32_t cells[(PCI_NUM_REGIONS +1 ) *5 ];int i, j;const char *name =NULL ;@@ -871,6 +871,7 @@ static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque) break; } } + node =g_string_new (NULL );g_string_printf (node,"%s/%s@%x" , fi->path, (name ?: pn),PCI_SLOT (d->devfn));if (PCI_FUNC(d->devfn)) {
Harsh Prateek Bora
AppliedQuoted 36 lines · BALATON Zoltan
Quoted 4 lines · Harsh Prateek Bora
Hi Balaton,
Thanks for taking care of this ...
Quoted 8 lines
Quoted 3 lines · BALATON Zoltan
Commit
9099b430a4introduced an early return that caused a leak of a GString. Allocate it later to avoid the leak.I think we also want to mention:
Reported-by Peter Maydell <[email protected]>You can add it on merge.
Quoted 7 lines
Quoted 7 lines
Fixes 9099b430a4 (hw/ppc/pegasos2: Change device tree generation)Resolves: Coverity CID 1642027
Signed-off-by BALATON Zoltan <[email protected]>---
hw/ppc/pegasos.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)Quoted 12 lines
hw/ppc/pegasos.c static struct { · line 850
Quoted 10 lines
hw/ppc/pegasos.c +1
-1@@ -847,7 +847,7 @@ static struct { static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque) { FDTInfo *fi = opaque; - GString *node = g_string_new(NULL); + GString *node;Curious to know if there were any technical reasons for not using
g_autoptrwhich Peter initially suggested ?
Quoted 1 line
Just thought it's simpler and more straight forward this way and saves a bit of unnecessary complication. We don't even allocate the string now when we exit, with
g_autoptrit might do some additional operations unnecessarily. As this function otherwise does not have multiple exit points just one free at the end works.
Queued, thanks.