7b03a79
From 2529a3fc4f987f93e0774af865ac7cb6557bd0c2 Mon Sep 17 00:00:00 2001
7b03a79
From: Benjamin Berg <bberg@redhat.com>
7b03a79
Date: Fri, 4 Feb 2022 22:50:28 +0100
7b03a79
Subject: [PATCH] core: Unset device ctx if it has been destroyed
7b03a79
7b03a79
Devices can outlive their context in some cases (in particular with
7b03a79
python garbage collection). Guard against this happening by clearing the
7b03a79
ctx pointer so that it is not pointing to uninitialized memory.
7b03a79
---
7b03a79
 libusb/core.c | 1 +
7b03a79
 1 file changed, 1 insertion(+)
7b03a79
7b03a79
diff --git a/libusb/core.c b/libusb/core.c
7b03a79
index 7893ac23..1c1ada14 100644
7b03a79
--- a/libusb/core.c
7b03a79
+++ b/libusb/core.c
7b03a79
@@ -2441,6 +2441,7 @@ void API_EXPORTED libusb_exit(libusb_context *ctx)
7b03a79
 	for_each_device(_ctx, dev) {
7b03a79
 		usbi_warn(_ctx, "device %d.%d still referenced",
7b03a79
 			dev->bus_number, dev->device_address);
7b03a79
+		DEVICE_CTX(dev) = NULL;
7b03a79
 	}
7b03a79
 
7b03a79
 	if (!list_empty(&_ctx->open_devs))