HydrologicEngineeringCenter / hec-dss

source code for HEC-DSS (Data Storage System)
MIT License
27 stars 7 forks source link

Eliminate memory leak identified by Cppcheck. #171

Closed MikeNeilson closed 1 year ago

MikeNeilson commented 1 year ago

An initial change to some code to prevent identified memory leaks.

MikeNeilson commented 1 year ago

Probably good to have feedback from others.

My other thought was just convert this file to C++ and use std::unique_ptr to encapsulate the memory until released on assignment. the interface would still be C linkage so using programs wouldn't know. Would likely be cleaner but is a more drastic change and pulls in an additional library (libstdc++).

EDIT: to be clear, that would be c++17. so if anymore remembers auto_ptr, that's been deprecated since C++11.

ktarbet commented 1 year ago

I'm not in favor of using C++ unless we had a larger strategy to introduce C++ into the whole code base in a bigger way.

MikeNeilson commented 1 year ago

Oh no!, the forbidden goto! :)

I challenge you to find a cleaner way to do that in plain C.