Skip to content
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

8263893: getPrinterNames() leaks nameArray if Java String allocation fails #3096

Closed
wants to merge 1 commit into from

Conversation

@aivanov-jdk
Copy link
Member

@aivanov-jdk aivanov-jdk commented Mar 19, 2021

If JNU_NewStringPlatform fails to allocate new Java String object for printer name, std::bad_alloc is thrown. The handler for the exception does not release the local reference to the nameArray, thus it will be leaked.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263893: getPrinterNames() leaks nameArray if Java String allocation fails

Reviewers

Download

To checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3096/head:pull/3096
$ git checkout pull/3096

To update a local copy of the PR:
$ git checkout pull/3096
$ git pull https://git.openjdk.java.net/jdk pull/3096/head

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Mar 19, 2021

👋 Welcome back aivanov! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Mar 19, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 19, 2021

@aivanov-jdk The following label will be automatically applied to this pull request:

  • 2d

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the 2d label Mar 19, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Mar 19, 2021

Webrevs

prrace
prrace approved these changes Mar 19, 2021
Copy link
Contributor

@prrace prrace left a comment

This is fine but there's not really a leak since when the caller returns to Java localrefs are released anyway.

@openjdk
Copy link

@openjdk openjdk bot commented Mar 19, 2021

@aivanov-jdk 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:

8263893: getPrinterNames() leaks nameArray if Java String allocation fails

Reviewed-by: prr, azvegint, kizune

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 15 new commits pushed to the master branch:

  • 118a49f: 8263846: Bad JNI lookup getFocusOwner in accessibility code on Mac OS X
  • cb742f9: 8255255: Update Apache Santuario (XML Signature) to version 2.2.1
  • d2c137d: 8263558: Possible NULL dereference in fast path arena free if ZapResourceArea is true
  • ab66d69: 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe
  • 5b8233b: 8263871: On sem_destroy() failing we should assert
  • 96e5c3f: 8263890: Broken links to Unicode.org
  • 4d9517d: 8263834: Work around gdb for HashtableEntry
  • 6fa6557: 8263825: Remove unused and commented out member from NTLMException
  • 77ebc11: 8263892: More modifier order fixes in java.base
  • 80d3ea0: 8263885: Use the blessed modifier order in java.sql/rowset/transation.xa
  • ... and 5 more: https://git.openjdk.java.net/jdk/compare/d41f75120ddbce4573a3fda1a7085941a61387f3...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Mar 19, 2021
@@ -175,6 +175,10 @@ static jobjectArray getPrinterNames(JNIEnv *env, DWORD flags) {
}
} catch (std::bad_alloc&) {
delete [] pPrinterEnum;
if (nameArray != NULL) {
Copy link
Member

@mrserb mrserb Mar 19, 2021

Not sure that we usually clean the local refs in the native JNI methods, that only required in the native loop which are never returned to the java(I have check that by the grep of env->NewObjectArray)

Copy link
Member Author

@aivanov-jdk aivanov-jdk Mar 24, 2021

You're right. It's not required: all local refs are cleared when the JNI method exits.
My reasoning was that env->DeleteLocalRef(utf_str) is called in the loop. Strictly, it's not required either. Yet if there's a large number of elements in the array, it could cause a problem.

I'm going to withdraw the PR as the fix is not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants