Don't increase refcount on the device returned by getParent() or getDevice().

It's better to be like libusbx itself here and not change the behavior.
But I've added a note to explain to never unref such a device.
This commit is contained in:
Luca Longinotti 2013-06-13 14:26:36 +02:00
parent 266ab299cc
commit ccdc2f6022
2 changed files with 10 additions and 4 deletions

View File

@ -71,7 +71,8 @@ JNIEXPORT void JNICALL METHOD_NAME(LibUsb, exit)
{
if (!context)
{
if (defaultContextRefcnt <= 0) {
if (defaultContextRefcnt <= 0)
{
illegalState(env, "default context is not initialized");
return;
}
@ -373,7 +374,7 @@ JNIEXPORT jobject JNICALL METHOD_NAME(LibUsb, getDevice)
libusb_device_handle *dev_handle = unwrapDeviceHandle(env, handle);
if (!dev_handle) return NULL;
return wrapDevice(env, libusb_ref_device(libusb_get_device(dev_handle)));
return wrapDevice(env, libusb_get_device(dev_handle));
}
/**

View File

@ -652,6 +652,10 @@ public final class LibUsb
/**
* Get the the parent from the specified device [EXPERIMENTAL].
*
* Please note that the reference count of the returned device is not
* increased. As such, do not *ever* call {@link #unrefDevice(Device))
* directly on the returned Device.
*
* @param device
* A device
* @return The device parent or NULL if not available. You should issue a
@ -820,8 +824,9 @@ public final class LibUsb
/**
* Get the underlying device for a handle.
*
* This function does not modify the reference count of the returned device,
* so do not feel compelled to unreference it when you are done.
* Please note that the reference count of the returned device is not
* increased. As such, do not *ever* call {@link #unrefDevice(Device))
* directly on the returned Device.
*
* @param handle
* a device handle.