MtpDatabase JNI: Fixed a memory-leak in getObjectPropertyValue().

The jstring "stringValue" was not never freed.
In the case where "str" was NULL the whole cleanup part (see "goto out")
was even skipped.
This patch makes getObjectPropertyValue() behave like
getObjectPropertyList().

Change-Id: I5a7ec3611036f5253a054b00064999bcd1d1c29e
This commit is contained in:
Martin Blumenstingl
2014-05-31 15:50:38 +02:00
parent 4f8785f28e
commit 17a24c58bb

View File

@ -428,16 +428,14 @@ MtpResponseCode MyMtpDatabase::getObjectPropertyValue(MtpObjectHandle handle,
case MTP_TYPE_STR:
{
jstring stringValue = (jstring)env->GetObjectArrayElement(stringValuesArray, 0);
const char* str = (stringValue ? env->GetStringUTFChars(stringValue, NULL) : NULL);
if (stringValue) {
const char* str = env->GetStringUTFChars(stringValue, NULL);
if (str == NULL) {
return MTP_RESPONSE_GENERAL_ERROR;
}
packet.putString(str);
env->ReleaseStringUTFChars(stringValue, str);
} else {
packet.putEmptyString();
}
env->DeleteLocalRef(stringValue);
break;
}
default: