Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent memory leaks during error/early exist #359

Closed
dschlaep opened this issue Jul 28, 2023 · 0 comments
Closed

Prevent memory leaks during error/early exist #359

dschlaep opened this issue Jul 28, 2023 · 0 comments

Comments

@dschlaep
Copy link
Member

Currently, we call LogError() when the code encounters a problem and, if the problem is an error, then we exit early (i.e., crash for SOILWAT2 -- in case of rSOILWAT2, we call the R_int.h function error() instead).

However, we are not de-allocating dynamically allocated memory. For a single SOILWAT2 run, the program crashes and the OS may/should clean it up. However, in rSOILWAT2, we return to the calling function prematurely, and this causes a memory leak. Similarly, if we will convert SOILWAT2 in the future to run with multiple threads, then a prematurely returning thread will cause a memory leak.

Suggested solution: after we identify the problem but before we call exit() (or similar), we need to de-allocate dynamically allocated memory.

@dschlaep dschlaep added this to the Clean code milestone Jul 28, 2023
@dschlaep dschlaep added the bug label Jul 28, 2023
@dschlaep dschlaep mentioned this issue Aug 30, 2023
@dschlaep dschlaep modified the milestones: Clean code, Release v7.2.0 Aug 30, 2023
N1ckP3rsl3y added a commit that referenced this issue Sep 30, 2023
* Properly handle a thrown error
    * Provide premature function exiting when an error is encountered
    * Guarantee memory will be freed and files are closed upon error
* Addresses #359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant