diff options
author | George Burgess IV <gbiv@google.com> | 2021-07-19 07:43:00 +0000 |
---|---|---|
committer | George Burgess <gbiv@google.com> | 2021-07-19 17:09:10 +0000 |
commit | e485264ff59612cc3235affa623b09a532891c7b (patch) | |
tree | 4b84576a87ead0a101e08e581f307276c36cdbc4 /media | |
parent | e8ad8b7ff455ef77e36018de4e59f53483b336c3 (diff) |
MTP: fix a memory leak
We unconditionally leak every instance that we `new` of this. Move it to
the stack to fix this, since it doesn't need to be on the heap.
Bug: 188752500
Test: TreeHugger
Change-Id: I24ed3bb29c5a6912398a9e00e7748fd406cf6a62
Diffstat (limited to 'media')
-rw-r--r-- | media/jni/android_mtp_MtpDevice.cpp | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp index ac89fecd9150..8436ba412b2d 100644 --- a/media/jni/android_mtp_MtpDevice.cpp +++ b/media/jni/android_mtp_MtpDevice.cpp @@ -416,20 +416,14 @@ android_mtp_MtpDevice_set_device_property_init_version(JNIEnv *env, jobject thiz return -1; } - MtpProperty* property = new MtpProperty(MTP_DEVICE_PROPERTY_SESSION_INITIATOR_VERSION_INFO, - MTP_TYPE_STR, true); - if (!property) { - env->ThrowNew(clazz_io_exception, "Failed to obtain property."); - return -1; - } - - if (property->getDataType() != MTP_TYPE_STR) { + MtpProperty property(MTP_DEVICE_PROPERTY_SESSION_INITIATOR_VERSION_INFO, MTP_TYPE_STR, true); + if (property.getDataType() != MTP_TYPE_STR) { env->ThrowNew(clazz_io_exception, "Unexpected property data type."); return -1; } - property->setCurrentValue(propertyStr); - if (!device->setDevicePropValueStr(property)) { + property.setCurrentValue(propertyStr); + if (!device->setDevicePropValueStr(&property)) { env->ThrowNew(clazz_io_exception, "Failed to obtain property value."); return -1; } |