Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[monodroid] Remove local reference to Java instance when done with it (…
…#1967) Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/627319 Fixes: https://developercommunity.visualstudio.com/content/problem/268148/jni-local-reference-table-overflow-issue-in-xamari.html Network interface information retrieval code needs to call a number of Java methods in order to obtain the information from the OS. A failure to free one of the retrieved local references caused a leak and a possible eventual crash: JNI ERROR (app bug): local reference table overflow (max=512) local reference table dump: Last 10 entries (of 512): 511: 0x12c53580 java.net.InterfaceAddress 510: 0x12c1d640 byte[] (16 elements) 509: 0x12c22358 java.net.Inet6Address 508: 0x12c37ac0 java.net.InterfaceAddress[] (1 elements) 507: 0x12c37ad0 java.net.InetAddress[] (1 elements) 506: 0x12c53550 byte[] (6 elements) 505: 0x12c1d780 java.lang.String "dummy0" 504: 0x12c04610 java.net.NetworkInterface 503: 0x12c37fe0 java.io.FileDescriptor 502: 0x12c56228 com.android.server.NetworkManagementSocketTagger Summary: 1 of java.net.Inet6Address 2 of java.io.FileDescriptor (2 unique instances) 2 of java.lang.String (2 unique instances) 1 of java.net.InetAddress[] (1 elements) 1 of byte[] (6 elements) 1 of byte[] (16 elements) 1 of java.net.InterfaceAddress[] (1 elements) 500 of java.net.NetworkInterface (500 unique instances) 1 of java.net.InterfaceAddress 2 of com.android.server.NetworkManagementSocketTagger (1 unique instances) Note the `500 of java.net.NetworkInterface` listing: that's the leak. Call `JNIEnv::DeleteLocalRef()` on the `NetworkInterface` instance so that we don't leak them, fixing the crash. Lumped together is a potential NULL dereference fix and an unnecessary signed comparison of unsigned operands.
- Loading branch information
71a98b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably partly resolves https://bugzilla.xamarin.com/show_bug.cgi?id=52733
(finally...)