From 1d46f4f2dd549bb8711ed12d3c638a9fbef5a18f Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 3 Feb 2021 09:45:08 -0800 Subject: [PATCH] Cast ApkAssets to uintptr_t before jlong Ever since 1e2456730d433551161f04b07e8b9524dd5b556a was submitted, we have been getting reports of leaking of fds owned by ApkAssets. The code that invokes the finalizer in NativeAllocationRegistry uses the following code to cast the jlong free function to the pointer of the native free function: void* nativePtr = reinterpret_cast(static_cast(ptr)); In ApkAssets, we should be doing the reverse of these casts to give NativeAllocationRegistry a pointer to a free function that will be interpreted correctly. Bug: 178571382 Test: manual Change-Id: I6cd3f5cc9fd3693a1288e0309e9e49b08c0d5316 --- core/jni/android_content_res_ApkAssets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/jni/android_content_res_ApkAssets.cpp b/core/jni/android_content_res_ApkAssets.cpp index af06e2e80cec5..c7439f1b32d43 100644 --- a/core/jni/android_content_res_ApkAssets.cpp +++ b/core/jni/android_content_res_ApkAssets.cpp @@ -354,7 +354,7 @@ static void NativeDestroy(void* ptr) { } static jlong NativeGetFinalizer(JNIEnv* /*env*/, jclass /*clazz*/) { - return reinterpret_cast(&NativeDestroy); + return static_cast(reinterpret_cast(&NativeDestroy)); } static jstring NativeGetAssetPath(JNIEnv* env, jclass /*clazz*/, jlong ptr) {