Reference state is not necessary when virEventAddTimeout failed, this may cause a memory leak, so reference state only when virEventAddTimeout success. Signed-off-by: Xu Yandong <xuyandong2@xxxxxxxxxx> --- src/conf/object_event.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/conf/object_event.c b/src/conf/object_event.c index 5d84598d59..ee5def5910 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -891,20 +891,21 @@ virObjectEventStateRegisterID(virConnectPtr conn, virObjectLock(state); if ((state->callbacks->count == 0) && - (state->timer == -1) && - (state->timer = virEventAddTimeout(-1, - virObjectEventTimer, - state, - virObjectFreeCallback)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("could not initialize domain event timer")); - goto cleanup; + (state->timer == -1)) { + if ((state->timer = virEventAddTimeout(-1, + virObjectEventTimer, + state, + virObjectFreeCallback)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not initialize domain event timer")); + goto cleanup; + } else { + /* event loop has one reference, but we need one more for the + * timer's opaque argument */ + virObjectRef(state); + } } - /* event loop has one reference, but we need one more for the - * timer's opaque argument */ - virObjectRef(state); - ret = virObjectEventCallbackListAddID(conn, state->callbacks, key, filter, filter_opaque, klass, eventID, -- 2.18.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list