Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add virtual dtor to classes with virtual functions
IncluderInterface has virtual functions but does not have a virtual destructor. This class is derived from by FileIncluder w hich overrides those functions. Because there is an interface in use here, it is safe to assume some container is storing IncluderInterface*. If the container instead held FileIncluder* then the virtual functions wouldn't be needed. This causes a problem since FileIncluder has member variables. The destructor of FileIncluder knows to also destruct those member variables (including deallocating their dynamically allocated memory). But when IncluderInterface's destructor is called, it is not virtual and will not call FileIncluder's destructor. So these member variables are never destroyed and their dynamically allocated memory will be leaked. In this case, FileIncluder stores a std::unordered_set<std::string> which will be leaked. This patch adds a virtual destructor to IncluderInterface to make sure FileIncluder's destructor is called and this memory isn't leaked. Use =default and don't redeclare IncluderInterface's dtor
- Loading branch information