From 18f307aed32d7a74a088fd871b90a5b9be86d8fa Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 24 Jan 2017 16:30:22 -0800 Subject: [PATCH] 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 --- core/jni/android_view_InputChannel.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/jni/android_view_InputChannel.cpp b/core/jni/android_view_InputChannel.cpp index c7998a169225f..1c6ead0f1086a 100644 --- a/core/jni/android_view_InputChannel.cpp +++ b/core/jni/android_view_InputChannel.cpp @@ -111,11 +111,12 @@ void android_view_InputChannel_setDisposeCallback(JNIEnv* env, jobject inputChan } static jobject android_view_InputChannel_createInputChannel(JNIEnv* env, - NativeInputChannel* nativeInputChannel) { + std::unique_ptr nativeInputChannel) { jobject inputChannelObj = env->NewObject(gInputChannelClassInfo.clazz, gInputChannelClassInfo.ctor); if (inputChannelObj) { - android_view_InputChannel_setNativeInputChannel(env, inputChannelObj, nativeInputChannel); + android_view_InputChannel_setNativeInputChannel(env, inputChannelObj, + nativeInputChannel.release()); } return inputChannelObj; } @@ -143,13 +144,13 @@ static jobjectArray android_view_InputChannel_nativeOpenInputChannelPair(JNIEnv* } jobject serverChannelObj = android_view_InputChannel_createInputChannel(env, - new NativeInputChannel(serverChannel)); + std::make_unique(serverChannel)); if (env->ExceptionCheck()) { return NULL; } jobject clientChannelObj = android_view_InputChannel_createInputChannel(env, - new NativeInputChannel(clientChannel)); + std::make_unique(clientChannel)); if (env->ExceptionCheck()) { return NULL; }