usb-gadget: make variable null after free 15/275815/2
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 2 Jun 2022 06:30:19 +0000 (15:30 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 2 Jun 2022 06:41:54 +0000 (15:41 +0900)
The SIGABRT(heap-use-after-free) was raised. It happened rarely when
the sdb is re-enabled after disabled due to unstable envrionment.
(But it is unclear what the unstable envrionment is.) To prevent this,
make a variable null after freeing it.

Change-Id: I2218004bf2069d6f8a6c835ba8883ece22f9c75b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/usb-gadget/usb-gadget-cfs-ops.c

index e33fcdf..7379f52 100644 (file)
@@ -582,6 +582,7 @@ err_no_udc:
        usbg_cleanup(g_cfs_client->ctx);
 err_usbg_init:
        free(g_cfs_client);
+       g_cfs_client = NULL;
 
        return ret;
 }
@@ -612,6 +613,7 @@ static int usb_gadget_cfs_close(void)
        usbg_rm_gadget(g_cfs_client->gadget, USBG_RM_RECURSE);
        usbg_cleanup(g_cfs_client->ctx);
        free(g_cfs_client);
+       g_cfs_client = NULL;
 
        return 0;
 }