chipsalliance / yosys-f4pga-plugins

Plugins for Yosys developed as part of the F4PGA project.
https://f4pga.org
Apache License 2.0
83 stars 46 forks source link

Fix memory leaks detected by ASAN. #534

Closed mglb closed 1 year ago

mglb commented 1 year ago

Fixes leaks and adds unique_resource class to make leaking from std::vector<AST::AstNode*> (and similar classes, but this one is used quite often) harder.

The unique_resource works like unique_ptr, but wraps object of any type (not only pointers) and uses provided Deleter functor to delete that resource when needed. Default deleter that deletes all pointers in the range is provided for any range of pointers (i.e. any type T where *std::begin(t) is a pointer when t is an object of that type).

The class is inspired by std::experimental::unique_resource, but the API is closed to unique_ptr. Main differences: