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
JDK-8257604: JNI_ArgumentPusherVaArg leaks valist #1565
JDK-8257604: JNI_ArgumentPusherVaArg leaks valist #1565
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
9858d47
to
4719617
Compare
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.
Looks good.
I added more history to the bug report.
@tstuefe This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 1 new commit pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
Thanks, Dan. Unfortunately, the issue is not visible to outsiders. But I guess there were platforms where va_copy was not available (like old versions of VS). |
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.
Looks good.
You can read this for historical copying of va_list args: But I'm not at all sure that our use of these macros in a RAII helper object is actually valid. From what I've read these macros have to be used in the same function in which the va_list was received. I'm also not clear why we call va_copy in the first place, as we only need that if the caller also needs to access the va list of arguments. Or perhaps if we need to ensure we actually have something we can pass to another function ... but in that case the va_copy should be in the same function where the va_start is (and the corresponding va_end). (Imagine if args were passed in registers, you'd need to call va_copy to copy them to the stack in the function in which the register still holds the arg.) |
E.g. I think this macro:
should be:
|
Though technically we still need the current code and proposed fix as we can't just do a direct assignment in the helper. Correction: technically va_copy and va_end are supposed to occur in the same function, so we're assuming our RAII object gets inlined if we think we're adhering to that. Perhaps I'm overthinking all this. It may not be "by the book" but it certainly seems to "work" okay so perhaps best not to rock the boat here. :) |
Hi David, I think the thoughts are valid, I thought it odd too. The usage of va_args is tightly defined. https://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdarg.h.html I also wondered why we copy in the first place, but as I wrote, I was not sure I missed some caller or some way the original ap got used. "not rocking the boat" - should I just withdraw this patch? Its a small theoretical leak. But I did a quick test on my Ubuntu box, leaking an va_list, and could not see any memory loss. Of course it may still be leaking on other platforms. Cheers, Thomas |
Hi Thomas, IIUC (and at best that is a partial understanding) the allocation of memory by va_start only happens under specific conditions, and I don't know exactly what they are. I tried going to the source: https://github.com/gcc-mirror/gcc/blob/master/gcc/builtins.c but that wasn't exactly illuminating without understanding all the other gcc-isms in use. (You may understand better than I.) I think your fix is harmless, and technically improves the existing code, even if there are potentially other flaws with how we do this. So if you and the other reviewers want to go ahead that seems fine to me. Thanks, |
Thank you Coleen, David and Dan. /integrate |
@tstuefe Since your change was applied there have been 13 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit ae1eb28. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
JNI_ArgumentPusherVaArg copies the given argument list pointer (va_copy) but never releases it. A call to va_end is missing.
AFAICS this coding is old. Interestingly, in jdk8 I find this:
_ap = rap
seems a strangely relaxed way of doing this. But I do not know the history behind that.I could not find any usage of the original arg pointer, so maybe the
va_copy()
is not even needed. The jdk8 coding seems to indicate that too. But since I was not 100% sure I kept theva_copy()
and added ava_end()
.I also made this private (removed the
protected
) since there are no child classes.Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1565/head:pull/1565
$ git checkout pull/1565