mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
object_event: reference state only if virEventAddTimeout succeeded
When registering new callback for an event, the event loop timer must be created and registered. The timer has domain event state object as an opaque argument which must be ref()-ed but only if the timer was being created and registered successfully. We must not ref it every time the virObjectEventStateRegisterID() runs. Signed-off-by: Xu Yandong <xuyandong2@huawei.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
b030f35e40
commit
89d724b157
@ -891,19 +891,20 @@ 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;
|
||||
}
|
||||
|
||||
/* 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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user