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

Commit 18f307ae authored by George Burgess IV's avatar George Burgess IV
Browse files

Fix memory-leak warnings from the static analyzer

Warnings:
frameworks/base/core/jni/android_view_InputChannel.cpp:145:5: warning:
Potential memory leak
jobject serverChannelObj =
android_view_InputChannel_createInputChannel(env,
^~~~~~~~~~~~~~~~~~~~~~~~
frameworks/base/core/jni/android_view_InputChannel.cpp:151:5: warning:
Potential memory leak
jobject clientChannelObj =
android_view_InputChannel_createInputChannel(env,
^~~~~~~~~~~~~~~~~~~~~~~~

The warnings were complaining about that we might leak
nativeInputChannel, in android_view_InputChannel_createInputChannel,
since we're allocating it as an arg and not always putting it somewhere.

Bug: None
Test: Builds without warnings
Change-Id: I62163adee5d420ad78c8d4c74aafefc8a58f765b
parent 01f2e676
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -111,11 +111,12 @@ void android_view_InputChannel_setDisposeCallback(JNIEnv* env, jobject inputChan
}
}


static jobject android_view_InputChannel_createInputChannel(JNIEnv* env,
static jobject android_view_InputChannel_createInputChannel(JNIEnv* env,
        NativeInputChannel* nativeInputChannel) {
        std::unique_ptr<NativeInputChannel> nativeInputChannel) {
    jobject inputChannelObj = env->NewObject(gInputChannelClassInfo.clazz,
    jobject inputChannelObj = env->NewObject(gInputChannelClassInfo.clazz,
            gInputChannelClassInfo.ctor);
            gInputChannelClassInfo.ctor);
    if (inputChannelObj) {
    if (inputChannelObj) {
        android_view_InputChannel_setNativeInputChannel(env, inputChannelObj, nativeInputChannel);
        android_view_InputChannel_setNativeInputChannel(env, inputChannelObj,
                 nativeInputChannel.release());
    }
    }
    return inputChannelObj;
    return inputChannelObj;
}
}
@@ -143,13 +144,13 @@ static jobjectArray android_view_InputChannel_nativeOpenInputChannelPair(JNIEnv*
    }
    }


    jobject serverChannelObj = android_view_InputChannel_createInputChannel(env,
    jobject serverChannelObj = android_view_InputChannel_createInputChannel(env,
            new NativeInputChannel(serverChannel));
            std::make_unique<NativeInputChannel>(serverChannel));
    if (env->ExceptionCheck()) {
    if (env->ExceptionCheck()) {
        return NULL;
        return NULL;
    }
    }


    jobject clientChannelObj = android_view_InputChannel_createInputChannel(env,
    jobject clientChannelObj = android_view_InputChannel_createInputChannel(env,
            new NativeInputChannel(clientChannel));
            std::make_unique<NativeInputChannel>(clientChannel));
    if (env->ExceptionCheck()) {
    if (env->ExceptionCheck()) {
        return NULL;
        return NULL;
    }
    }