hw/timer/cadence_ttc: move timer_new from init() into realize() to avoid memleaks
There are some memleaks when we call 'device_list_properties'. This patch move timer_new from init into realize to fix it. Reported-by: Euler Robot <euler.robot@huawei.com> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-id: 20200227025055.14341-7-pannengyuan@huawei.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
efb27a49af
commit
f4228077e8
@ -412,18 +412,23 @@ static void cadence_timer_init(uint32_t freq, CadenceTimerState *s)
|
||||
static void cadence_ttc_init(Object *obj)
|
||||
{
|
||||
CadenceTTCState *s = CADENCE_TTC(obj);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
cadence_timer_init(133000000, &s->timer[i]);
|
||||
sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->timer[i].irq);
|
||||
}
|
||||
|
||||
memory_region_init_io(&s->iomem, obj, &cadence_ttc_ops, s,
|
||||
"timer", 0x1000);
|
||||
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
|
||||
}
|
||||
|
||||
static void cadence_ttc_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
CadenceTTCState *s = CADENCE_TTC(dev);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
cadence_timer_init(133000000, &s->timer[i]);
|
||||
sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->timer[i].irq);
|
||||
}
|
||||
}
|
||||
|
||||
static int cadence_timer_pre_save(void *opaque)
|
||||
{
|
||||
cadence_timer_sync((CadenceTimerState *)opaque);
|
||||
@ -479,6 +484,7 @@ static void cadence_ttc_class_init(ObjectClass *klass, void *data)
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
|
||||
dc->vmsd = &vmstate_cadence_ttc;
|
||||
dc->realize = cadence_ttc_realize;
|
||||
}
|
||||
|
||||
static const TypeInfo cadence_ttc_info = {
|
||||
|
Loading…
Reference in New Issue
Block a user