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

Commit a3820cb1 authored by Orion Hodson's avatar Orion Hodson Committed by Automerger Merge Worker
Browse files

Merge changes from topic "lnh-jifd-leak" am: f900f378 am: 55857b67 am: a352757a

Change-Id: Ia766e1e0b52b79f39472804d7a8f47270eab9b44
parents dcb45285 a352757a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -510,7 +510,11 @@ static jobject android_os_Parcel_readFileDescriptor(JNIEnv* env, jclass clazz, j
        if (fd < 0) return NULL;
        fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
        if (fd < 0) return NULL;
        return jniCreateFileDescriptor(env, fd);
        jobject jifd = jniCreateFileDescriptor(env, fd);
        if (jifd == NULL) {
            close(fd);
        }
        return jifd;
    }
    return NULL;
}
+5 −1
Original line number Diff line number Diff line
@@ -69,7 +69,11 @@ jobject SharedMemory_nCreate(JNIEnv* env, jobject, jstring jname, jint size) {
        return nullptr;
    }

    return jniCreateFileDescriptor(env, fd);
    jobject jifd = jniCreateFileDescriptor(env, fd);
    if (jifd == nullptr) {
        close(fd);
    }
    return jifd;
}

jint SharedMemory_nGetSize(JNIEnv* env, jobject, jobject fileDescriptor) {
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ static jobject android_server_SerialService_open(JNIEnv *env, jobject /* thiz */

    jobject fileDescriptor = jniCreateFileDescriptor(env, fd);
    if (fileDescriptor == NULL) {
        close(fd);
        return NULL;
    }
    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
+13 −16
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include "jni.h"
#include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedUtfChars.h>
#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"
#include "MtpDescriptors.h"
@@ -88,6 +89,7 @@ static jobject android_server_UsbDeviceManager_openAccessory(JNIEnv *env, jobjec
    }
    jobject fileDescriptor = jniCreateFileDescriptor(env, fd);
    if (fileDescriptor == NULL) {
        close(fd);
        return NULL;
    }
    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
@@ -120,35 +122,30 @@ static jint android_server_UsbDeviceManager_getAudioMode(JNIEnv* /* env */, jobj
}

static jobject android_server_UsbDeviceManager_openControl(JNIEnv *env, jobject /* thiz */, jstring jFunction) {
    const char *function = env->GetStringUTFChars(jFunction, NULL);
    ScopedUtfChars function(env, jFunction);
    bool ptp = false;
    int fd = -1;
    if (!strcmp(function, "ptp")) {
    if (!strcmp(function.c_str(), "ptp")) {
        ptp = true;
    }
    if (!strcmp(function, "mtp") || ptp) {
    if (!strcmp(function.c_str(), "mtp") || ptp) {
        fd = TEMP_FAILURE_RETRY(open(ptp ? FFS_PTP_EP0 : FFS_MTP_EP0, O_RDWR));
        if (fd < 0) {
            ALOGE("could not open control for %s %s", function, strerror(errno));
            goto error;
            ALOGE("could not open control for %s %s", function.c_str(), strerror(errno));
            return NULL;
        }
        if (!writeDescriptors(fd, ptp)) {
            goto error;
            close(fd);
            return NULL;
        }
    }

    if (function != NULL) {
        env->ReleaseStringUTFChars(jFunction, function);
    }
    return jniCreateFileDescriptor(env, fd);
error:
    if (fd != -1) {
    jobject jifd = jniCreateFileDescriptor(env, fd);
    if (jifd == NULL) {
        // OutOfMemoryError will be pending.
        close(fd);
    }
    if (function != NULL) {
        env->ReleaseStringUTFChars(jFunction, function);
    }
    return NULL;
    return jifd;
}

static const JNINativeMethod method_table[] = {
+1 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ static jobject android_server_UsbHostManager_openDevice(JNIEnv *env, jobject /*

    jobject fileDescriptor = jniCreateFileDescriptor(env, newFD);
    if (fileDescriptor == NULL) {
        close(newFD);
        return NULL;
    }
    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
Loading