When using virtual classes, the destructor needs to be virtual so that the derived object destructor gets called instead of the base class. Running AddressSanitizer revealed the bug, the BaseCachePolicy destructor was being called for the derived CachePolicy objects.
Moreover, fixing a potential bug in SieveCachePolicy due to accessing uninitialized class member function before the object is constructed. It is better to ensure it is constructed manually.
Checklist
Please feel free to remove inapplicable items for your PR.
[ ] The PR title starts with [$CATEGORY] (such as [NN], [Model], [Doc], [Feature]])
[ ] I've leverage the tools to beautify the python and c++ code.
[ ] The PR is complete and small, read the Google eng practice (CL equals to PR) to understand more about small PR. In DGL, we consider PRs with less than 200 lines of core code change are small (example, test and documentation could be exempted).
[ ] All changes have test coverage
[ ] Code is well-documented
[ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
[ ] Related issue is referred in this PR
[ ] If the PR is for a new model/paper, I've updated the example index here.
@dgl-bot run [instance-type] [which tests] [compare-with-branch];
For example: @dgl-bot run g4dn.4xlarge all dmlc/master or @dgl-bot run c5.9xlarge kernel,api dmlc/master
Description
When using virtual classes, the destructor needs to be virtual so that the derived object destructor gets called instead of the base class. Running AddressSanitizer revealed the bug, the
BaseCachePolicy
destructor was being called for the derivedCachePolicy
objects.More information about it is here: https://learn.microsoft.com/en-us/cpp/cpp/destructors-cpp?view=msvc-170#order-of-destruction
Moreover, fixing a potential bug in
SieveCachePolicy
due to accessing uninitialized class member function before the object is constructed. It is better to ensure it is constructed manually.Checklist
Please feel free to remove inapplicable items for your PR.
Changes