libusbx/libusbx — pull request #116 by llongi (2013-06-12 18:55:02+00:00)
Title: Fix calling libusb_exit(NULL) when the default context doesn't yet exist or was already destroyed

Hi, right now just calling libusb_exit(NULL) without a libusb_init(NULL) before it segfaults. If the refcount is already 0, it just goes down to -1 and ctx will be NULL, which leads to a NULL-ptr dereference right away inside libusb_exit().
Since the default context is reference counted, you'd expect this to be detected and ignored, instead of segfaulting. It's a simple check, as shown in the pull request.