lcpp-org / RustBCA

A free, open-source Binary Collision Approximation (BCA) code for ion-material interactions including sputtering, implantation, and reflection
https://github.com/lcpp-org/RustBCA/wiki
GNU General Public License v3.0
42 stars 15 forks source link

Memory management #227

Closed drobnyjt closed 1 year ago

drobnyjt commented 1 year ago

Thank you for your contribution to rustBCA!

Before submitting this PR, please make sure you have:

Fixes #226

Description

It turns out that even if Rust forgets a raw pointer, it cannot be safely freed once C takes ownership. This PR adds a couple of cleanup functions that correctly dispose of structs with raw pointers when coupling to C to prevent memory leaking.

Tests

cargo test passes and RustBCA.c was used with valgrind to show that this fixes the leak. See the linked issue above.