From d657a38d874283455cdcca1b3bd70af77dd8c1a4 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 20 Jun 2017 23:53:29 -0700 Subject: [PATCH] Fix static analyzer complaints frameworks/base/core/jni/android_view_MotionEvent.cpp:383:12: warning: Potential leak of memory pointed to by 'event' frameworks/base/core/jni/AndroidRuntime.cpp:975:20: warning: Null passed to a callee that requires a non-null 1st parameter For the former, it was surprising to me that the analyzer couldn't figure out that `event == nativePtr` for the latter check. Filed https://bugs.llvm.org/show_bug.cgi?id=33540 upstream about it. For the latter, it was complaining because `className` could be NULL (more precisely, we have a NULL check at the top of the function it's declared in, so NULL is presumably a valid value). Bug: None Test: Ran mma; complaints are gone. Change-Id: I26a91ae25934f95acbfdbe4f3641e081fbc66c6d --- core/jni/AndroidRuntime.cpp | 2 +- core/jni/android_view_MotionEvent.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index facc0f998bdaa..23d3ead44d3fd 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -1094,7 +1094,7 @@ void AndroidRuntime::start(const char* className, const Vector& options * Start VM. This thread becomes the main thread of the VM, and will * not return until the VM exits. */ - char* slashClassName = toSlashClassName(className); + char* slashClassName = toSlashClassName(className != NULL ? className : ""); jclass startClass = env->FindClass(slashClassName); if (startClass == NULL) { ALOGE("JavaVM unable to locate class '%s'\n", slashClassName); diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp index 0245d38144cbb..f38d8e4c68be7 100644 --- a/core/jni/android_view_MotionEvent.cpp +++ b/core/jni/android_view_MotionEvent.cpp @@ -345,8 +345,10 @@ static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz return 0; } - MotionEvent* event = reinterpret_cast(nativePtr); - if (!event) { + MotionEvent* event; + if (nativePtr) { + event = reinterpret_cast(nativePtr); + } else { event = new MotionEvent(); }