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

8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386 #10378

Closed
wants to merge 5 commits into from

Conversation

alisenchung
Copy link
Contributor

@alisenchung alisenchung commented Sep 21, 2022

changed return to cleanup in getAllConfigs
changed cleanup to loop thru and free all allocated memory adjacent to graphicsConfig pointer


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10378/head:pull/10378
$ git checkout pull/10378

Update a local copy of the PR:
$ git checkout pull/10378
$ git pull https://git.openjdk.org/jdk pull/10378/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10378

View PR using the GUI difftool:
$ git pr show -t 10378

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10378.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 21, 2022

👋 Welcome back achung! 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 Pull request is ready for review label Sep 21, 2022
@openjdk
Copy link

openjdk bot commented Sep 21, 2022

@alisenchung The following label will be automatically applied to this pull request:

  • client

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 client client-libs-dev@openjdk.org label Sep 21, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 21, 2022

Webrevs

for (int i = 0; i < screenDataPtr->numConfigs; i++) {
if (graphicsConfigs[i] != 0) {
free(graphicsConfigs[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems screenDataPtr->numConfigs is updated only when success = JNI_TRUE and here we are checking if success != JNI_TRUE condition, so amnot sure if we will be getting the correct updated configs number.
I think condition should be i< ind-1 which is updated before every allocation, but it should be verified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "nConfig" would have been the better value to use.
Look at how the array is allocated and that it is zeroed out
nConfig = n8p + n12p + n8s + n8gs + n8sg + n1sg + nTrue + 1;
graphicsConfigs = (AwtGraphicsConfigDataPtr *)
calloc(nConfig, sizeof(AwtGraphicsConfigDataPtr));

So it should always be safe.

@@ -572,6 +572,11 @@ getAllConfigs (JNIEnv *env, int screen, AwtScreenDataPtr screenDataPtr) {

cleanup:
if (success != JNI_TRUE) {
for (int i = 0; i < ind-1; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New int i declaration shadows previously declared i, I think it can be reused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried building without the new int i and it does seem to be fine. Probably worth it to follow the rest of the class's format and reuse the i var for getAllConfigs.

@@ -572,6 +572,11 @@ getAllConfigs (JNIEnv *env, int screen, AwtScreenDataPtr screenDataPtr) {

cleanup:
if (success != JNI_TRUE) {
for (int i = 0; i < ind-1; i++) {
if (graphicsConfigs[i] != 0) {
Copy link
Member

@azvegint azvegint Sep 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine as it is, but this check can be omitted since free is no-op for null pointer arguments.

@openjdk
Copy link

openjdk bot commented Sep 30, 2022

@alisenchung 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:

8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386

Reviewed-by: azvegint, dnguyen

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

  • 3644e26: 8294673: JFR: Add SecurityProviderService#threshold to TestActiveSettingEvent.java
  • 085949a: 8294712: G1: Use index-base iteration for G1FlushHumongousCandidateRemSets
  • b850f05: 8294758: JFR: Docs build fails after changes to RecordedObject and Timespan
  • 2dbedf0: 8294406: Test runtime/handshake/HandshakeDirectTest.java failed: JVMTI_ERROR_WRONG_PHASE
  • 4d6668e: 8294242: JFR: jfr print doesn't handle infinite duration well
  • 5a9cd33: 8294509: The sign extension bug applies to 'public static int[] convertSeedBytesToInts(byte[] seed, int n, int z)' in RandomSupport
  • f03934e: 8294578: [PPC64] C2: Missing is_oop information when using disjoint compressed oops mode
  • 3b476a1: 8292847: Zero: Allow ergonomics to select the GC
  • 16047e8: 8292780: misc tests failed "assert(false) failed: graph should be schedulable"
  • bf39b18: 8288302: Shenandoah: SIGSEGV in vm maybe related to jit compiling xerces
  • ... and 587 more: https://git.openjdk.org/jdk/compare/ea2c82e74f5580f396920f9e561cbec80c03f373...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@azvegint) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 30, 2022
@alisenchung
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 3, 2022
@openjdk
Copy link

openjdk bot commented Oct 3, 2022

@alisenchung
Your change (at version f49c034) is now ready to be sponsored by a Committer.

@azvegint
Copy link
Member

azvegint commented Oct 4, 2022

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 4, 2022

Going to push as commit 1166a8a.
Since your change was applied there have been 597 commits pushed to the master branch:

  • 3644e26: 8294673: JFR: Add SecurityProviderService#threshold to TestActiveSettingEvent.java
  • 085949a: 8294712: G1: Use index-base iteration for G1FlushHumongousCandidateRemSets
  • b850f05: 8294758: JFR: Docs build fails after changes to RecordedObject and Timespan
  • 2dbedf0: 8294406: Test runtime/handshake/HandshakeDirectTest.java failed: JVMTI_ERROR_WRONG_PHASE
  • 4d6668e: 8294242: JFR: jfr print doesn't handle infinite duration well
  • 5a9cd33: 8294509: The sign extension bug applies to 'public static int[] convertSeedBytesToInts(byte[] seed, int n, int z)' in RandomSupport
  • f03934e: 8294578: [PPC64] C2: Missing is_oop information when using disjoint compressed oops mode
  • 3b476a1: 8292847: Zero: Allow ergonomics to select the GC
  • 16047e8: 8292780: misc tests failed "assert(false) failed: graph should be schedulable"
  • bf39b18: 8288302: Shenandoah: SIGSEGV in vm maybe related to jit compiling xerces
  • ... and 587 more: https://git.openjdk.org/jdk/compare/ea2c82e74f5580f396920f9e561cbec80c03f373...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 4, 2022
@openjdk openjdk bot closed this Oct 4, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Oct 4, 2022
@openjdk
Copy link

openjdk bot commented Oct 4, 2022

@azvegint @alisenchung Pushed as commit 1166a8a.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants