From b81b7d964400a40c3839c5e9c9cadd7b97a00f8c Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Tue, 22 Sep 2020 14:20:48 +0900 Subject: [PATCH] dfu: add null check for thread If dfu_start() is failed, there are cases ctx->thread is null and this causes crash during dfu_free_context(). So add null check for thread from dfu_free_context(). This fixes below crash-stack: Call Stack Count: 2 0: pthread_cancel + 0x10 (0x0000007f81d9eab0) [/mnt/initrd-recovery/usr/lib64/libpthread.so.0] + 0x10ab0 1: dfu_free_context + 0x1c (0x000000557ca2283c) [/mnt/initrd-recovery/usr/bin/flash-manager] + 0x483c End of Call Stack Change-Id: I92fb9980047a3a58de516e81d694b7507662be26 Signed-off-by: Seung-Woo Kim --- src/dfu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dfu.c b/src/dfu.c index c7d1039..362016a 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -644,7 +644,8 @@ void dfu_free_context(struct dfu_context *ctx) if (!ctx) return; - pthread_cancel(ctx->thread); + if (ctx->thread) + pthread_cancel(ctx->thread); destroy_dfu_info(ctx); free(ctx); } -- 2.7.4