diff mbox

iothread: check iothread->ctx before aio_context_unref to avoid assertion

Message ID 20160926052958.10716-1-lma@suse.com
State New
Headers show

Commit Message

Lin Ma Sept. 26, 2016, 5:29 a.m. UTC
if iothread->ctx is set to NULL, aio_context_unref triggers the assertion:
g_source_unref: assertion 'source != NULL' failed.
The patch fixes it.

Signed-off-by: Lin Ma <lma@suse.com>
---
 iothread.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Paolo Bonzini Sept. 26, 2016, 7:06 a.m. UTC | #1
On 26/09/2016 07:29, Lin Ma wrote:
> if iothread->ctx is set to NULL, aio_context_unref triggers the assertion:
> g_source_unref: assertion 'source != NULL' failed.
> The patch fixes it.
> 
> Signed-off-by: Lin Ma <lma@suse.com>
> ---
>  iothread.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/iothread.c b/iothread.c
> index fb08a60..fbeb8de 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -75,6 +75,9 @@ static void iothread_instance_finalize(Object *obj)
>      iothread_stop(obj, NULL);
>      qemu_cond_destroy(&iothread->init_done_cond);
>      qemu_mutex_destroy(&iothread->init_done_lock);
> +    if (!iothread->ctx) {
> +        return;
> +    }
>      aio_context_unref(iothread->ctx);
>  }
>  
> 

This only happens if there is an error, but it's theoretically possible.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Stefan Hajnoczi Sept. 26, 2016, 2:25 p.m. UTC | #2
On Mon, Sep 26, 2016 at 01:29:58PM +0800, Lin Ma wrote:
> if iothread->ctx is set to NULL, aio_context_unref triggers the assertion:
> g_source_unref: assertion 'source != NULL' failed.
> The patch fixes it.
> 
> Signed-off-by: Lin Ma <lma@suse.com>
> ---
>  iothread.c | 3 +++
>  1 file changed, 3 insertions(+)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan
diff mbox

Patch

diff --git a/iothread.c b/iothread.c
index fb08a60..fbeb8de 100644
--- a/iothread.c
+++ b/iothread.c
@@ -75,6 +75,9 @@  static void iothread_instance_finalize(Object *obj)
     iothread_stop(obj, NULL);
     qemu_cond_destroy(&iothread->init_done_cond);
     qemu_mutex_destroy(&iothread->init_done_lock);
+    if (!iothread->ctx) {
+        return;
+    }
     aio_context_unref(iothread->ctx);
 }