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

JDK-8261601: free memory in early return in Java_sun_nio_ch_sctp_SctpChannelImpl_receive0 #2540

Closed
wants to merge 1 commit into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Feb 12, 2021

There seems to be an early return in Java_sun_nio_ch_sctp_SctpChannelImpl_receive0 that misses freeing memory.

Sonar reports :
https://sonarcloud.io/project/issues?id=shipilev_jdk&languages=c&open=AXck8Cl0BBG2CXpcnjFu&resolved=false&severities=BLOCKER&types=BUG

Potential leak of memory pointed to by 'newBuf'
I adjusted the early return and added freeing memory .

Btw. while adjusting Java_sun_nio_ch_sctp_SctpChannelImpl_receive0 , I started to wonder what happens to the allocated memory in the same file in handleSendFailed ( if ((addressP = malloc(dataLength)) == NULL) ) in early return cases incl. the CHECK_NULL , is there some deallocation missing there too ?


Progress

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

Issue

  • JDK-8261601: free memory in early return in Java_sun_nio_ch_sctp_SctpChannelImpl_receive0

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2540/head:pull/2540
$ git checkout pull/2540

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 12, 2021

👋 Welcome back mbaesken! 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 Feb 12, 2021
@openjdk
Copy link

openjdk bot commented Feb 12, 2021

@MBaesken The following labels will be automatically applied to this pull request:

  • net
  • security

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

@openjdk openjdk bot added security security-dev@openjdk.org net net-dev@openjdk.org labels Feb 12, 2021
@mlbridge
Copy link

mlbridge bot commented Feb 12, 2021

Webrevs

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk
Copy link

openjdk bot commented Feb 12, 2021

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

8261601: free memory in early return in Java_sun_nio_ch_sctp_SctpChannelImpl_receive0

Reviewed-by: clanger, dfuchs, bpb

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

  • 350303d: 8260221: java.util.Formatter throws wrong exception for mismatched flags in %% conversion
  • 6475d47: 8261655: [PPC64] Build broken after JDK-8260941
  • c0e805a: 8261654: Missing license header in Signatures.java
  • b670efd: 8261072: AArch64: Fix MacroAssembler::get_thread convention
  • 59b8d59: 8261481: Cannot read Kerberos settings in dynamic store on macOS Big Sur
  • 9f81ca8: 8261230: GC tracing of page sizes are wrong in a few places
  • 40ae993: 8261027: AArch64: Support for LSE atomics C++ HotSpot code
  • 9ffabf3: 8252971: WindowsFileAttributes does not know about Unix domain sockets
  • 682e78e: 8261071: AArch64: Refactor interpreter native wrappers
  • ebaa58d: 8261505: Test test/hotspot/jtreg/gc/parallel/TestDynShrinkHeap.java killed by Linux OOM Killer
  • ... and 4 more: https://git.openjdk.java.net/jdk/compare/6a84ec68c3e20ef971ab523e82e178b6ab4e371e...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 Pull request is ready to be integrated label Feb 12, 2021
dfuch
dfuch approved these changes Feb 12, 2021
Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

LGTM

@dfuch
Copy link
Member

dfuch commented Feb 12, 2021

@MBaesken did you run the jdk_sctp tests?

@MBaesken
Copy link
Member Author

MBaesken commented Feb 12, 2021

@MBaesken did you run the jdk_sctp tests?

Hi, the com/sun/nio/sctp jtreg tests passed on linux x86_64. I'll put it into our internal build/test queue to see over night what it does on all the platforms.

@MBaesken
Copy link
Member Author

MBaesken commented Feb 12, 2021

Btw. while adjusting Java_sun_nio_ch_sctp_SctpChannelImpl_receive0 , I started to wonder what happens to the allocated >memory in the same file in handleSendFailed ( if ((addressP = malloc(dataLength)) == NULL) ) in early return cases incl. the >CHECK_NULL , is there some deallocation missing there too ?

hi, any comments on this ? See SctpChannelImpl.c
SctpChannelImpl.c

the malloc there is followed by a few early returns, where is the memory freed is these cases ?

bplb
bplb approved these changes Feb 12, 2021
Copy link
Member

@bplb bplb left a comment

Choose a reason for hiding this comment

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

This change looks fine. I don't know about handleSendFailed().

@AlanBateman
Copy link
Contributor

Btw. while adjusting Java_sun_nio_ch_sctp_SctpChannelImpl_receive0 , I started to wonder what happens to the allocated memory in the same file in handleSendFailed ( if ((addressP = malloc(dataLength)) == NULL) ) in early return cases incl. the CHECK_NULL , is there some deallocation missing there too ?

Yes, the error paths in handleSendFailed should be looked at. If NewDirectByteBuffer or recvmsg fails then addressP needs to be freed. Furthermore, if the NewObject fails and bufferObj != NULL then the memory for the direct buffer will need to be freed too (as JNI NewDirectByteBuffer does not setup a cleaner).

@MBaesken
Copy link
Member Author

/integrate

@openjdk openjdk bot closed this Feb 16, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 16, 2021
@openjdk
Copy link

openjdk bot commented Feb 16, 2021

@MBaesken Since your change was applied there have been 40 commits pushed to the master branch:

  • e2d52ae: 8261413: Shenandoah: Disable class-unloading in I-U mode
  • 34ae7ae: 8261609: remove remnants of XML-driven builders
  • 6badd22: 8261351: Create implementation for NSAccessibilityRadioButton protocol
  • 849f4c0: 8260291: The case instruction is not visible in dark mode
  • 2e610f5: 8260687: Inherited font size is smaller than expected when using StyleSheet to add styles
  • 3882fda: 8260414: Remove unused set_single_threaded_mode() method in task executor
  • c6eedda: 8261500: Shenandoah: reconsider region live data memory ordering
  • df0897e: 8261504: Shenandoah: reconsider ShenandoahJavaThreadsIterator::claim memory ordering
  • 745c0b9: 8261493: Shenandoah: reconsider bitmap access memory ordering
  • 4642730: 8261496: Shenandoah: reconsider pacing updates memory ordering
  • ... and 30 more: https://git.openjdk.java.net/jdk/compare/6a84ec68c3e20ef971ab523e82e178b6ab4e371e...master

Your commit was automatically rebased without conflicts.

Pushed as commit cdc874d.

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

@AlanBateman
Copy link
Contributor

I see this has been integrated but the fix is incomplete. Are you planning to create a follow-on issue for the issues that I pointed out above?

@MBaesken
Copy link
Member Author

MBaesken commented Feb 16, 2021

I see this has been integrated but the fix is incomplete. Are you planning to create a follow-on issue for the issues that I pointed out above?

Hi Alan, thanks about your comment to my question about handleSendFailed .
I opened a follow-on for this : https://bugs.openjdk.java.net/browse/JDK-8261791

Best regards, Matthias

@MBaesken MBaesken deleted the JDK-8261601 branch Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org security security-dev@openjdk.org
5 participants