[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC 2/5] qemu_thread_join: fix segmentation faul
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH RFC 2/5] qemu_thread_join: fix segmentation fault |
Date: |
Thu, 29 Nov 2018 15:32:11 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 |
Hi Fei,
On 28/11/18 11:33, Fei Li wrote:
> To avoid the segmentation fault in qemu_thread_join(), just directly
> return when the QemuThread *thread failed to be created in either
> qemu-thread-posix.c or qemu-thread-win32.c.
>
> Signed-off-by: Fei Li <address@hidden>
> Reviewed-by: Fam Zheng <address@hidden>
> ---
> util/qemu-thread-posix.c | 3 +++
> util/qemu-thread-win32.c | 2 +-
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index 865e476df5..b9ab5a4711 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -558,6 +558,9 @@ void *qemu_thread_join(QemuThread *thread)
> int err;
> void *ret;
>
> + if (!thread->thread) {
> + return NULL;
> + }
> err = pthread_join(thread->thread, &ret);
> if (err) {
> error_exit(err, __func__);
> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> index 4a363ca675..1a27e1cf6f 100644
> --- a/util/qemu-thread-win32.c
> +++ b/util/qemu-thread-win32.c
> @@ -366,7 +366,7 @@ void *qemu_thread_join(QemuThread *thread)
> HANDLE handle;
>
> data = thread->data;
> - if (data->mode == QEMU_THREAD_DETACHED) {
> + if (data == NULL || data->mode == QEMU_THREAD_DETACHED) {
Isn't it a way to hide a problem from the caller?
qemu_thread_create() always initializes thread->data.
If the thread doesn't exist you shouldn't try to join() it.
If you try to fix a bug, I'd use here:
assert(thread->data);
Regards,
Phil.
> return NULL;
> }
>
>
- [Qemu-devel] [PATCH RFC 0/5] fix some segmentation faults and migration issues, Fei Li, 2018/11/28
- [Qemu-devel] [PATCH RFC 4/5] migration: remove unused &local_err parameter in multifd_save_cleanup, Fei Li, 2018/11/28
- [Qemu-devel] [PATCH RFC 5/5] migration: add more error handling for postcopy_ram_enable_notify, Fei Li, 2018/11/28
- [Qemu-devel] [PATCH RFC 3/5] migration: fix the multifd code when receiving less channels, Fei Li, 2018/11/28
- [Qemu-devel] [PATCH RFC 2/5] qemu_thread_join: fix segmentation fault, Fei Li, 2018/11/28
- Re: [Qemu-devel] [PATCH RFC 2/5] qemu_thread_join: fix segmentation fault,
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH RFC 1/5] Fix segmentation fault when qemu_signal_init fails, Fei Li, 2018/11/28