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

David Holmes david.holmes at oracle.com
Fri Feb 5 08:46:02 UTC 2021


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

> Best regards, Matthias
> 
> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/2409
> 


More information about the hotspot-runtime-dev mailing list