Skip to content

Commit

Permalink
Fix memory leak in experiment: JNI leak
Browse files Browse the repository at this point in the history
Summary: I think this array is copied when we call the function over the JNI, and that we need to free the local copy we make.

Reviewed By: mdvacca

Differential Revision: D17377077

fbshipit-source-id: 82fe4ec89e95335a329f4ce562441561dbe88693
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Sep 14, 2019
1 parent 87af32a commit 4b59360
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -489,7 +489,16 @@ local_ref<JMountItem::javaobject> createRemoveAndDeleteMultiMountItem(
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jintArray)>("removeDeleteMultiMountItem");

return removeDeleteMultiInstruction(javaUIManager, removeAndDeleteArray);
auto ret = removeDeleteMultiInstruction(javaUIManager, removeAndDeleteArray);

// It is not strictly necessary to manually delete the ref here, in this particular case.
// If JNI memory is being allocated in a loop, it's easy to overload the localref table
// and crash; this is not possible in this case since the JNI would automatically clear this
// ref when it goes out of scope, anyway. However, this is being left here as a reminder of
// good hygiene and to be careful with JNI-allocated memory in general.
env->DeleteLocalRef(removeAndDeleteArray);

return ret;
}

// TODO T48019320: because we pass initial props and state to the Create (and preallocate) mount instruction,
Expand Down

0 comments on commit 4b59360

Please sign in to comment.