diff --git a/cli/pg2-util/dfu_load.c b/cli/pg2-util/dfu_load.c index f8941ab..b8caa05 100644 --- a/cli/pg2-util/dfu_load.c +++ b/cli/pg2-util/dfu_load.c @@ -204,7 +204,7 @@ bool dfu_load(const firmware_image_t *image, libusb_device *dev, libusb_device * /* wait for the new device to appear */ post_hotplug = hotplug_await(hotplug_state); if (loaded_device) - *loaded_device = libusb_ref_device(post_hotplug); + *loaded_device = post_hotplug ? libusb_ref_device(post_hotplug) : NULL; cleanup: if (handle) diff --git a/cli/pg2-util/mem_load.c b/cli/pg2-util/mem_load.c index f99601f..2188fe1 100644 --- a/cli/pg2-util/mem_load.c +++ b/cli/pg2-util/mem_load.c @@ -103,7 +103,7 @@ bool mem_load(const firmware_image_t *image, libusb_device *dev, libusb_device * /* wait for the new device to appear */ post_hotplug = hotplug_await(hotplug_state); if (loaded_device) - *loaded_device = libusb_ref_device(post_hotplug); + *loaded_device = post_hotplug ? libusb_ref_device(post_hotplug) : NULL; cleanup: if (handle)