Skip to content

Commit caa5d82

Browse files
pm215philmd
authored andcommitted
hw/misc/riscv_cpc: Free CPU array in instance_finalize
The TYPE_RISCV_CPC device allocates an array in its instance_init, but does not free this, leading to leaks like this from QOM/QMP introspection: Direct leak of 512 byte in 1 object allocated from: #0 in calloc #1 in g_malloc0 #2 in riscv_cpc_init /home/pm215/qemu/build/san/../../hw/misc/riscv_cpc.c:175:15 #3 in object_initialize_with_type /home/pm215/qemu/build/san/../../qom/object.c:570:5 #4 in object_new_with_type /home/pm215/qemu/build/san/../../qom/object.c:774:5 #5 in qmp_device_list_properties /home/pm215/qemu/build/san/../../qom/qom-qmp-cmds.c:206:11 #6 in qdev_device_help /home/pm215/qemu/build/san/../../system/qdev-monitor.c:313:17 #7 in hmp_device_add /home/pm215/qemu/build/san/../../system/qdev-monitor.c:1005:9 Free the array in instance_finalize. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
1 parent ac9dde4 commit caa5d82

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

hw/misc/riscv_cpc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ static void riscv_cpc_init(Object *obj)
185185
}
186186
}
187187

188+
static void riscv_cpc_finalize(Object *obj)
189+
{
190+
RISCVCPCState *s = RISCV_CPC(obj);
191+
192+
g_free(s->cpus);
193+
}
194+
188195
static void riscv_cpc_realize(DeviceState *dev, Error **errp)
189196
{
190197
RISCVCPCState *s = RISCV_CPC(dev);
@@ -254,6 +261,7 @@ static const TypeInfo riscv_cpc_info = {
254261
.parent = TYPE_SYS_BUS_DEVICE,
255262
.instance_size = sizeof(RISCVCPCState),
256263
.instance_init = riscv_cpc_init,
264+
.instance_finalize = riscv_cpc_finalize,
257265
.class_init = riscv_cpc_class_init,
258266
};
259267

0 commit comments

Comments
 (0)