Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f8c6023 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

UsbService: Fix JNI local reference leaks in the USB host support code



Bug: 4175857

Change-Id: I8b385f2257e509b0fb4d5f9516e9813b8165352d
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 0b9bacc6
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -117,9 +117,14 @@ static int usb_device_added(const char *devname, void* client_data) {
    jintArray endpointArray = env->NewIntArray(length);
    jintArray endpointArray = env->NewIntArray(length);
    env->SetIntArrayRegion(endpointArray, 0, length, endpointValues.array());
    env->SetIntArrayRegion(endpointArray, 0, length, endpointValues.array());


    jstring deviceName = env->NewStringUTF(devname);
    env->CallVoidMethod(thiz, method_usbDeviceAdded,
    env->CallVoidMethod(thiz, method_usbDeviceAdded,
            env->NewStringUTF(devname), vendorId, productId, deviceClass,
            deviceName, vendorId, productId, deviceClass,
            deviceSubClass, protocol, interfaceArray, endpointArray);
            deviceSubClass, protocol, interfaceArray, endpointArray);

    env->DeleteLocalRef(interfaceArray);
    env->DeleteLocalRef(endpointArray);
    env->DeleteLocalRef(deviceName);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);


    return 0;
    return 0;
@@ -129,7 +134,9 @@ static int usb_device_removed(const char *devname, void* client_data) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jobject thiz = (jobject)client_data;
    jobject thiz = (jobject)client_data;


    jstring deviceName = env->NewStringUTF(devname);
    env->CallVoidMethod(thiz, method_usbDeviceRemoved, env->NewStringUTF(devname));
    env->CallVoidMethod(thiz, method_usbDeviceRemoved, env->NewStringUTF(devname));
    env->DeleteLocalRef(deviceName);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
    return 0;
    return 0;
}
}