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

Daniel D.Daugherty dcubed at openjdk.java.net
Thu Feb 4 18:18:41 UTC 2021


On Thu, 4 Feb 2021 16:54:57 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

> 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

Changes requested by dcubed (Reviewer).

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) {`

-------------

PR: https://git.openjdk.java.net/jdk/pull/2409


More information about the hotspot-runtime-dev mailing list