[libvirt] [PATCH] event: reference state only when virEventAddTimeout success
Daniel Henrique Barboza
danielhb413 at gmail.com
Thu Sep 19 14:00:28 UTC 2019
On 9/19/19 5:02 AM, Xu Yandong wrote:
> 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 at huawei.com>
> ---
Reviewed-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
> 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,
More information about the libvir-list
mailing list