LLNL / sundials

Official development repository for SUNDIALS - a SUite of Nonlinear and DIfferential/ALgebraic equation Solvers. Pull requests are welcome for bug fixes and minor changes.
https://computing.llnl.gov/projects/sundials
BSD 3-Clause "New" or "Revised" License
523 stars 131 forks source link

Error Handler Memory Leak #466

Closed Steven-Roberts closed 7 months ago

Steven-Roberts commented 7 months ago

If more than default error handler is added to a SUNContext, it does not get free'd in SUNContext_Free.

https://github.com/LLNL/sundials/blob/2abd63bd6cbc354fb4861bba8e98d0b95d65e24a/src/sundials/sundials_context.c#L288

https://github.com/LLNL/sundials/blob/2abd63bd6cbc354fb4861bba8e98d0b95d65e24a/src/sundials/sundials_errors.c#L42-L47

Either SUNContext_Free or SUNErrHandler_Destroy should traverse the list of error handlers through sunctx->err_handler->previous to free each.

gardner48 commented 7 months ago

https://github.com/LLNL/sundials/blob/2abd63bd6cbc354fb4861bba8e98d0b95d65e24a/src/sundials/sundials_context.c#L288

This call to SUNErrHandler_Destory should be replaced with SUNContext_ClearErrHandlers

Steven-Roberts commented 7 months ago

Ah great, there's already a function to do that. I swapped in SUNContext_ClearErrHandlers and valgrind reports no leaks. I'll turn it into a PR.

balos1 commented 7 months ago

Closed by #467