Skip to contentSkip to conversation

hw/ppc/mac_newworld: Free openpic_irqs array after use

PATCH Applied Peter Maydell 4 participants 5 messages Nov 1, 2018 – Nov 4, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/ppc/mac_newworld: Free openpic_irqs array after use

In ppc_core99_init(), we allocate an openpic_irqs array, which we then use to collect up the various qemu_irqs which we're going to connect to the interrupt controller. Once we've called sysbus_connect_irq() to connect them all up, the array is no longer required, but we forgot to free it.

Since board init is only run once at startup, the memory leak is not a significant one.

Spotted by Coverity: CID 1192916.

---
 hw/ppc/mac_newworld.c | 1 +
 1 file changed, 1 insertion(+)
hw/ppc/mac_newworld.c +1 -0
index a630cb81cd8..14273a123e5 100644
@@ -303,6 +303,7 @@ static void ppc_core99_init(MachineState *machine)
             sysbus_connect_irq(s, k++, openpic_irqs[i][j]);
         }
     }
+    g_free(openpic_irqs);
 
     if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
         /* 970 gets a U3 bus */
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Peter Maydell

In ppc_core99_init(), we allocate an openpic_irqs array, which we then use to collect up the various qemu_irqs which we're going to connect to the interrupt controller. Once we've called sysbus_connect_irq() to connect them all up, the array is no longer required, but we forgot to free it.

Quoted 6 lines

Since board init is only run once at startup, the memory leak is not a significant one.

Spotted by Coverity: CID 1192916.

Quoted 17 lines
---
  hw/ppc/mac_newworld.c | 1 +
  1 file changed, 1 insertion(+)
hw/ppc/mac_newworld.c +1 -0
index a630cb81cd8..14273a123e5 100644
@@ -303,6 +303,7 @@ static void ppc_core99_init(MachineState *machine)
              sysbus_connect_irq(s, k++, openpic_irqs[i][j]);
          }
      }
+    g_free(openpic_irqs);
 
      if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
          /* 970 gets a U3 bus */
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell
Quoted 22 lines · Peter Maydell

In ppc_core99_init(), we allocate an openpic_irqs array, which we then use to collect up the various qemu_irqs which we're going to connect to the interrupt controller. Once we've called sysbus_connect_irq() to connect them all up, the array is no longer required, but we forgot to free it.

Since board init is only run once at startup, the memory leak is not a significant one.

Spotted by Coverity: CID 1192916.

---
 hw/ppc/mac_newworld.c | 1 +
 1 file changed, 1 insertion(+)
hw/ppc/mac_newworld.c +0 -0
index a630cb81cd8..14273a123e5 100644

hw/ppc/mac_newworld.c static void ppc_core99_init(MachineState *machine) · line 309

Quoted 7 lines
hw/ppc/mac_newworld.c +1 -0
@@ -303,6 +303,7 @@ static void ppc_core99_init(MachineState *machine)
             sysbus_connect_irq(s, k++, openpic_irqs[i][j]);
         }
     }
+    g_free(openpic_irqs);
 
     if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
         /* 970 gets a U3 bus */

I did notice the generation of this 2D array for the OpenPIC controller whilst converting the Mac machines over to qdev, but wasn't exactly sure what to do here so I left it.

ATB,

Mark.

#3 lore raw
Quoted 34 lines · Mark Cave-Ayland
Quoted 22 lines · Peter Maydell

In ppc_core99_init(), we allocate an openpic_irqs array, which we then use to collect up the various qemu_irqs which we're going to connect to the interrupt controller. Once we've called sysbus_connect_irq() to connect them all up, the array is no longer required, but we forgot to free it.

Since board init is only run once at startup, the memory leak is not a significant one.

Spotted by Coverity: CID 1192916.

---
 hw/ppc/mac_newworld.c | 1 +
 1 file changed, 1 insertion(+)
hw/ppc/mac_newworld.c +0 -0
index a630cb81cd8..14273a123e5 100644

hw/ppc/mac_newworld.c static void ppc_core99_init(MachineState *machine) · line 309

Quoted 7 lines
hw/ppc/mac_newworld.c +1 -0
@@ -303,6 +303,7 @@ static void ppc_core99_init(MachineState *machine)
             sysbus_connect_irq(s, k++, openpic_irqs[i][j]);
         }
     }
+    g_free(openpic_irqs);
 
     if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
         /* 970 gets a U3 bus */
Quoted 3 lines

I did notice the generation of this 2D array for the OpenPIC controller whilst converting the Mac machines over to qdev, but wasn't exactly sure what to do here so I left it.

In some sense the array isn't really necessary at all -- instead of "fill in array with things; create PIC; sysbus_connect_irq from array" you could just do "create PIC; sysbus_connect_irq to things". But for this patch I opted to just free the memory rather than attempt more complicated refactoring.

thanks
-- PMM

Applied
#4 lore raw
In reply to Peter Maydell
Quoted 6 lines · Peter Maydell

In ppc_core99_init(), we allocate an openpic_irqs array, which we then use to collect up the various qemu_irqs which we're going to connect to the interrupt controller. Once we've called sysbus_connect_irq() to connect them all up, the array is no longer required, but we forgot to free it.

Quoted 6 lines

Since board init is only run once at startup, the memory leak is not a significant one.

Spotted by Coverity: CID 1192916.

Applied, thanks.

Quoted 16 lines
---
 hw/ppc/mac_newworld.c | 1 +
 1 file changed, 1 insertion(+)
hw/ppc/mac_newworld.c +1 -0
index a630cb81cd8..14273a123e5 100644
@@ -303,6 +303,7 @@ static void ppc_core99_init(MachineState *machine)
             sysbus_connect_irq(s, k++, openpic_irqs[i][j]);
         }
     }
+    g_free(openpic_irqs);
 
     if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
         /* 970 gets a U3 bus */
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson