dfu: add null check for thread 74/244574/1
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 22 Sep 2020 05:20:48 +0000 (14:20 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 22 Sep 2020 05:20:51 +0000 (14:20 +0900)
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 <sw0312.kim@samsung.com>
src/dfu.c

index c7d1039..362016a 100644 (file)
--- 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);
 }