Fix memory leak of lastArray when newArray == NULL
lastArray remains copied/pinned when android_os_Process_getPids returns
early because of a failure to allocate newArray.
Bug: 351917521
Test: cuttlefish boot
Change-Id: I95ebeb36ffc185a21acca11b9393b6dd8f4e0f83
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index 43bfa7c..3ac1892 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -818,7 +818,6 @@
}
DIR* dirp = opendir(file8);
-
env->ReleaseStringUTFChars(file, file8);
if(dirp == NULL) {
@@ -851,6 +850,7 @@
jintArray newArray = env->NewIntArray(newCount);
if (newArray == NULL) {
closedir(dirp);
+ if (curData) env->ReleaseIntArrayElements(lastArray, curData, 0);
jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
return NULL;
}