Describe the bug
load_rational_damping_api can leak memory if an invalid method is passed in.
The problem stems from here: https://github.com/dftd4/dftd4/blob/main/src/dftd4/api.f90#L456
If it fails to allocate param%ptr, the function returns early, leaving vparam =c_null_ptr. Since vparam is never assigned c_loc(params), we can't find/deallocate param after the function returns
To Reproduce
Pass a bad functional name into dftd4_load_rational_damping in a program using the C-api. Running the program with valgrind, you should a memory leak, even if you catch the error and run dftd4_delete_param
Expected behaviour
Deallocate param in dftd4_load_rational_damping if it fails. Alternatively, return the pointer and allow dftd4_delete_param to handle deletion.
Additional context
I will open a pull request to fix this shortly, as it seems to be a quick fix. It's a fairly minor bug in the meantime.
Describe the bug
load_rational_damping_apican leak memory if an invalid method is passed in.The problem stems from here: https://github.com/dftd4/dftd4/blob/main/src/dftd4/api.f90#L456
If it fails to allocate
param%ptr, the function returns early, leavingvparam =c_null_ptr. Sincevparamis never assignedc_loc(params), we can't find/deallocateparamafter the function returnsTo Reproduce
Pass a bad functional name into
dftd4_load_rational_dampingin a program using the C-api. Running the program with valgrind, you should a memory leak, even if you catch the error and rundftd4_delete_paramExpected behaviour
Deallocate
paramindftd4_load_rational_dampingif it fails. Alternatively, return the pointer and allowdftd4_delete_paramto handle deletion.Additional context
I will open a pull request to fix this shortly, as it seems to be a quick fix. It's a fairly minor bug in the meantime.