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-8261167: print_process_memory_info add a close call after fopen #2409

Closed
wants to merge 2 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Feb 4, 2021

Hello, there is an fopen call opening "proc/self/status" in print_process_memory_info in os_linux.cpp. This call should also have a corresponding fclose-call.

See also the Sonar finding ("Opened stream never closed. Potential resource leak") :
https://sonarcloud.io/project/issues?id=shipilev_jdk&open=AXck8BNvBBG2CXpcnaeA&resolved=false&severities=BLOCKER&types=BUG


Progress

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

Issue

  • JDK-8261167: print_process_memory_info add a close call after fopen

Reviewers

Download

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 4, 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 4, 2021
@openjdk
Copy link

openjdk bot commented Feb 4, 2021

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

  • hotspot-runtime

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 hotspot-runtime hotspot-runtime-dev@openjdk.org label Feb 4, 2021
@mlbridge
Copy link

mlbridge bot commented Feb 4, 2021

Webrevs

Copy link
Member

@tstuefe tstuefe 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 4, 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:

8261167: print_process_memory_info add a close call after fopen

Reviewed-by: stuefe, dholmes

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

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 4, 2021
)
{
num_found ++;
if (f) {
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use implied booleans. This should be:
if (f != NULL) {

Copy link
Member

Choose a reason for hiding this comment

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

What Dan said. Plus if you are now checking the fopen succeeded shouldn't you also print something if it failed?

Thanks,
David

Copy link
Member Author

Choose a reason for hiding this comment

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

hi Daniel and David, I added a NULL check, and some output.
I noticed that a number of other fopen calls miss the NULL check + output in case of failure as well, should I adjust that in another change?

Best regards, Matthias

)
{
num_found ++;
if (f) {
Copy link
Member

Choose a reason for hiding this comment

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

What Dan said. Plus if you are now checking the fopen succeeded shouldn't you also print something if it failed?

Thanks,
David

@mlbridge
Copy link

mlbridge bot commented Feb 5, 2021

Mailing list message from David Holmes on hotspot-runtime-dev:

On 5/02/2021 6:08 pm, Matthias Baesken wrote:

On Thu, 4 Feb 2021 23:29:52 GMT, David Holmes <dholmes at openjdk.org> wrote:

src/hotspot/os/linux/os_linux.cpp line 2198:

2196: FILE* f = ::fopen("/proc/self/status", "r");
2197: char buf[256];
2198: if (f) {

Please don't use implied booleans. This should be:
`if (f != NULL) {`

What Dan said. Plus if you are now checking the fopen succeeded shouldn't you also print something if it failed?

Thanks,
David

hi Daniel and David, I added a NULL check, and some output.
I noticed that a number of other fopen calls miss the NULL check + output in case of failure as well, should I adjust that in another change?

I guess so. Though the output will depend on context - some things you
won't be able to print an error message.

I'm trying to recall if there was some discussion that these /proc open
calls really can't fail hence the lack of checking ...

Cheers,
David

@MBaesken
Copy link
Member Author

MBaesken commented Feb 5, 2021

I'm trying to recall if there was some discussion that these /proc open
calls really can't fail hence the lack of checking ...

Hi David, those other calls are checked but just in the style if (fp) { ... }
without the explicit NULL check .
For example

FILE *fp = fopen("/proc/self/maps", "r");

@MBaesken
Copy link
Member Author

MBaesken commented Feb 5, 2021

/integrate

@openjdk openjdk bot closed this Feb 5, 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 5, 2021
@openjdk
Copy link

openjdk bot commented Feb 5, 2021

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

Your commit was automatically rebased without conflicts.

Pushed as commit 43ae0cf.

💡 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
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
4 participants