Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resource leak in Java bindings
20-06-2013, 10:10 PM (This post was last modified: 20-06-2013 10:11 PM by simoncn.)
Post: #1
Resource leak in Java bindings
I've discovered a resource leak in the Java bindings. The callback references created by InitParams.setLogOutput() and InitParams.setFatalErrorHandler() aren't being freed when the ohNet library is closed.

At first sight, this might not seem like a big problem, but it has some very unfortunate side-effects. These unfreed references prevent the classloader from being garbage collected, which in turn prevents the ohNet native libraries from being unloaded, which means the Java application can't re-initialize ohNet from a new classloader.

I've created a patch to fix this. It requires changes to the following files:

InitParams.c
InitParams.h
InitParams.java
Library.java

I'm attaching a zip file containing the full updated versions of all these files and diffs for the changes. I've tested the changes on Windows and Linux and I've confirmed that this resolves the classloader issues.

While doing this, I noticed some CR/LF line ending problems in InitParams.java and Library.java, and I've included changes to convert these CR/LF endings into LF endings.


Attached File(s)
.zip  callback.zip (Size: 11.17 KB / Downloads: 3)
Find all posts by this user
25-06-2013, 08:01 AM
Post: #2
RE: Resource leak in Java bindings
(20-06-2013 10:10 PM)simoncn Wrote:  I've discovered a resource leak in the Java bindings. The callback references created by InitParams.setLogOutput() and InitParams.setFatalErrorHandler() aren't being freed when the ohNet library is closed.

....

I've created a patch to fix this.

Thanks for tracking this down! I've applied the changes now so they should be on github this evening.
Find all posts by this user
26-06-2013, 08:53 PM
Post: #3
RE: Resource leak in Java bindings
(25-06-2013 08:01 AM)simonc Wrote:  Thanks for tracking this down! I've applied the changes now so they should be on github this evening.

Thanks very much! I've downloaded and tested the latest tag from github and it is working fine so far.
Find all posts by this user
10-07-2013, 08:21 PM
Post: #4
RE: Resource leak in Java bindings
(26-06-2013 08:53 PM)simoncn Wrote:  Thanks very much! I've downloaded and tested the latest tag from github and it is working fine so far.

I've found a similar problem in the control point stack (related to property callbacks). A patch is attached. Please let me know if you have any questions about the changes.


Attached File(s)
.zip  property.zip (Size: 1.18 KB / Downloads: 2)
Find all posts by this user
11-07-2013, 01:53 PM
Post: #5
RE: Resource leak in Java bindings
(10-07-2013 08:21 PM)simoncn Wrote:  I've found a similar problem in the control point stack (related to property callbacks). A patch is attached. Please let me know if you have any questions about the changes.

Thanks again. I've applied the patch as-is; it should be on github this evening.
Find all posts by this user
12-07-2013, 03:18 PM
Post: #6
RE: Resource leak in Java bindings
(11-07-2013 01:53 PM)simonc Wrote:  Thanks again. I've applied the patch as-is; it should be on github this evening.

It looks like this change hasn't made it to github yet.
Find all posts by this user
12-07-2013, 03:20 PM
Post: #7
RE: Resource leak in Java bindings
(12-07-2013 03:18 PM)simoncn Wrote:  
(11-07-2013 01:53 PM)simonc Wrote:  Thanks again. I've applied the patch as-is; it should be on github this evening.

It looks like this change hasn't made it to github yet.

A separate change of mine broke the Windows-x64 build, blocking publication of the code. That problem is now fixed so I've manually pushed to github. Your changes are available there now.
Find all posts by this user
15-07-2013, 02:21 PM
Post: #8
RE: Resource leak in Java bindings
(12-07-2013 03:20 PM)simonc Wrote:  A separate change of mine broke the Windows-x64 build, blocking publication of the code. That problem is now fixed so I've manually pushed to github. Your changes are available there now.

Thanks very much! I've downloaded the tag and confirmed that the problem is fixed.
Find all posts by this user


Forum Jump: