memory leak in JNI write functions fixed

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@270 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
spandi
2008-12-20 08:44:46 +00:00
parent 7c6ebbe8fa
commit fae4615b79
5 changed files with 49 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?> <?fileVersion 4.0.0?>
<cproject> <cproject>
@@ -47,11 +47,7 @@
</scannerInfoProvider> </scannerInfoProvider>
</profile> </profile>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
<pathentry kind="src" path=""/>
<pathentry kind="out" path=""/>
<pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/>
</storageModule>
<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="converted.config.1096271423" moduleId="org.eclipse.cdt.core.settings" name="convertedConfig"> <storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="converted.config.1096271423" moduleId="org.eclipse.cdt.core.settings" name="convertedConfig">
<externalSettings/> <externalSettings/>
<extensions> <extensions>
@@ -59,6 +55,13 @@
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
<pathentry kind="src" path=""/>
<pathentry kind="out" path=""/>
<pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/>
</storageModule>
</cconfiguration> </cconfiguration>
</storageModule> </storageModule>
</cproject> </cproject>

View File

@@ -665,9 +665,10 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1control_1msg
{ {
clearLibusbJavaError(); clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL); jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
int retVal = usb_control_msg((usb_dev_handle *) dev_handle, requesttype, request, value, index, (char *) bytes, size, timeout); int num_bytes = usb_control_msg((usb_dev_handle *) dev_handle, requesttype, request, value, index, (char *) bytes, size, timeout);
env->SetByteArrayRegion(jbytes, 0, size, bytes); env->SetByteArrayRegion(jbytes, 0, size, bytes);
return retVal; env->ReleaseByteArrayElements(jbytes, bytes, 0);
return num_bytes;
} }
/* /*
@@ -746,7 +747,9 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write
{ {
clearLibusbJavaError(); clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL); jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
return usb_bulk_write((usb_dev_handle *) dev_handle, ep, (char *) bytes, size, timeout); int num_bytes = usb_bulk_write((usb_dev_handle *) dev_handle, ep, (char *) bytes, size, timeout);
env->ReleaseByteArrayElements(jbytes, bytes, 0);
return num_bytes;
} }
/* /*
@@ -759,11 +762,11 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1read
{ {
clearLibusbJavaError(); clearLibusbJavaError();
char *bytes = (char *) malloc(size * sizeof(char)); char *bytes = (char *) malloc(size * sizeof(char));
int retVal = usb_bulk_read((usb_dev_handle *) dev_handle, ep, bytes, size, timeout); int num_bytes = usb_bulk_read((usb_dev_handle *) dev_handle, ep, bytes, size, timeout);
if (!bytes) { return retVal; } if (!bytes) { return num_bytes; }
env->SetByteArrayRegion(jbytes, 0, size, (jbyte *) bytes); env->SetByteArrayRegion(jbytes, 0, size, (jbyte *) bytes);
free(bytes); free(bytes);
return retVal; return num_bytes;
} }
/* /*
@@ -776,7 +779,9 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write
{ {
clearLibusbJavaError(); clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL); jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
return usb_interrupt_write((usb_dev_handle *) dev_handle, ep, (char *) bytes, size, timeout); int num_bytes = usb_interrupt_write((usb_dev_handle *) dev_handle, ep, (char *) bytes, size, timeout);
env->ReleaseByteArrayElements(jbytes, bytes, 0);
return num_bytes;
} }
/* /*
@@ -789,11 +794,11 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1read
{ {
clearLibusbJavaError(); clearLibusbJavaError();
char *bytes = (char *) malloc(size * sizeof(char)); char *bytes = (char *) malloc(size * sizeof(char));
int retVal = usb_interrupt_read((usb_dev_handle *) dev_handle, ep, bytes, size, timeout); int num_bytes = usb_interrupt_read((usb_dev_handle *) dev_handle, ep, bytes, size, timeout);
if (!bytes) { return retVal; } if (!bytes) { return num_bytes; }
env->SetByteArrayRegion(jbytes, 0, size, (jbyte *) bytes); env->SetByteArrayRegion(jbytes, 0, size, (jbyte *) bytes);
free(bytes); free(bytes);
return retVal; return num_bytes;
} }
/* /*

View File

@@ -20,7 +20,7 @@ BEGIN
VALUE "FileDescription", RC_PRODUCT_STR VALUE "FileDescription", RC_PRODUCT_STR
VALUE "FileVersion", RC_VERSION_STR VALUE "FileVersion", RC_VERSION_STR
VALUE "InternalName", RC_FILE_NAME_STR VALUE "InternalName", RC_FILE_NAME_STR
VALUE "LegalCopyright", "2005 spandi@users.sourceforge.net" VALUE "LegalCopyright", "2008 spandi@users.sourceforge.net"
VALUE "OriginalFilename",RC_FILE_NAME_STR VALUE "OriginalFilename",RC_FILE_NAME_STR
VALUE "ProductName", RC_PRODUCT_STR VALUE "ProductName", RC_PRODUCT_STR
VALUE "ProductVersion", RC_VERSION_STR VALUE "ProductVersion", RC_VERSION_STR

View File

@@ -2,6 +2,6 @@
#define RC_FILE_SUB_TYPE VFT2_UNKNOWN #define RC_FILE_SUB_TYPE VFT2_UNKNOWN
#define RC_PRODUCT_STR "Java LibUsb-Win32 wrapper - DLL" #define RC_PRODUCT_STR "Java LibUsb-Win32 wrapper - DLL"
#define RC_FILE_NAME_STR "LibusbJava.dll" #define RC_FILE_NAME_STR "LibusbJava.dll"
#define RC_VERSION_STR "0.2.3.0" #define RC_VERSION_STR "0.2.4.0"
#include "common.rc" #include "common.rc"

View File

@@ -1,5 +1,5 @@
# NOTE: if the version is changed -> change the define in resource.rc # NOTE: if the version is changed -> change the define in resource.rc
version.major=0 version.major=0
version.minor=2 version.minor=2
version.micro=3 version.micro=4
version.nano=0 version.nano=0