jacobwilliams / json-fortran

A Modern Fortran JSON API
https://jacobwilliams.github.io/json-fortran/
Other
332 stars 83 forks source link

Deserialize empty list leads to a memory leak #488

Closed tidus004 closed 3 years ago

tidus004 commented 3 years ago

Hi All,

I am not 100% whether this is an error that I encountering as I am not entirely an expert on the json-fortran library, but it seems to me that when I deserialize a json file that consists of an empty library, I get a memory leak.

For instance, when running the following simple code through valgrind

type(json_file) :: json call json%deserialize('{"Substance":[]}')

I get the following error

Screenshot 2021-07-27 at 13 05 16

The code perfectly runs and does exactly what I am expecting and no errors. A simple way that I will use to fix the error is just to remove empty lists from the message, but it's definitely consuming computational power.

I am missing something?

Thanks!

jacobwilliams commented 3 years ago

I'll take a look.

What compiler are you using? And what version of json-fortran (the latest 8.2.3 release?)

tidus004 commented 3 years ago

gfortran GNU Fortran (Homebrew GCC 11.1.0_1) 11.1.0

I am compiling and using the latest version on the website.

jacobwilliams commented 3 years ago

Thanks for reporting this!

On the 488-empty-array-leak branch now,

valgrind --leak-check=full \
         --show-leak-kinds=all \
         --track-origins=yes \
         --verbose \
         --log-file=valgrind-out.txt ./jf_test_49

now gives All heap blocks were freed -- no leaks are possible

tidus004 commented 3 years ago

Super!