Skip to content

Small memory leak for load_rational_damping_api #195

@TyBalduf

Description

@TyBalduf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIAffects the C-binding layer.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions