-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug with recursive IP_ADDR_STRING ByReference #986
Fix bug with recursive IP_ADDR_STRING ByReference #986
Conversation
I tested with JNA master and could not reproduce the issue with the unittests. I tested on Windows 10 with Oracle Java 8 (32+64 bit). Can you come up with a reproducer? I have a bad feeling merging this without being able to reproduce it. |
As mentioned on the mailing list. This rarely occurs on the first time, I have to repeatedly call it to generate the error. The following code reliably reproduces the error for me (this is exactly what's in the testcase, minus the various asserts.) The Exception occurs in the
Log... note it worked fine 5 times. (Other times it's done only 1, sometimes I've gotten over 40.)
Sometimes the trace is different. This may have to do with recursive calls as it traverses the linked list.
Does not error out on my home machine (Mac running virtualized Windows 7) but I can reproduce at will on my work machine:
Other notes:
|
So, I'm looking at this code again, and it just hit me. The error is occurring when I initialize So the initialization doesn't encounter problems when the new buffer is zeroed out (a "fresh" JVM) which has expected |
And... suspicion confirmed. The error goes away when I replace
with
I can also "fix" the error by both forcing garbage collection and waiting at least 500 milliseconds before instantiating the new So I'm not sure whether it's Java side or C side or both, or whether it's my bug or JNA's, but at least I know what's happening now! |
New structures with newly-allocated memory should always be using
"AutoAllocated", which clears memory on creation.
That's not the case when you create a Memory object explicitly and use it
as the base pointer.
Usually you'd need to override size() or provide a different constructure
so that the proper size is delivered to the auto-allocation.
…On Thu, Jul 19, 2018 at 1:07 AM, dbwiddis ***@***.***> wrote:
And... suspicion confirmed. The error goes away when I replace
FIXED_INFO buffer = new FIXED_INFO(new Memory(bufferSize.getValue()));
with
Memory mem = new Memory(bufferSize.getValue());
mem.clear(); // <--- this line fixes the error
FIXED_INFO buffer = new FIXED_INFO(mem);
I can also "fix" the error by both forcing garbage collection and waiting
at least 500 milliseconds.
So I'm not sure whether it's Java side or C side or both, or whether it's
my bug or JNA's, but at least I know what's happening now!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#986 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAuMreXFROzpH97Pw1dCuRSxr4rA9ZvKks5uIBQYgaJpZM4VG3rc>
.
|
Thanks, @twall. I'd come to that conclusion, that using the |
OK, I've got it all sorted out. The error was trying to cast the memory to Also the version of |
Thank you for the fix - looks right. The explanation (in review with you observations) is in the definition of The change call sequence (allocate memory, let it be initialized by This is also explains why it works at first, as at that point you will get newly allocated memory, that is initialized by the OS, later you will get memory that the application already used and freed. |
While the
GetNetworkParams
testcase in #983 worked fine on my Windows7 machine, it created Invalid Access Errors on Win 10, probably related to a combination recursive pre-reading of ByReference structures in the constructor, and local thread caching. See JNA mailing list thread for details. Bottom line: theIP_ADDR_STRING
linked list needs to be mapped as aPointer
and the linked list traversed manually.