Getting Runtime Error
\nclass Solution {\n    unordered_map<int, bool> mmap;\npublic:\n    void delNodesHelper(TreeNode* root, vector<TreeNode*>& res, TreeNode* parent, bool left)\n 
```\nclass Solution {\n    unordered_map<int, bool> mmap;\npublic:\n    void delNodesHelper(TreeNode* root, vector<TreeNode*>& res, TreeNode* parent, bool left)\n    {\n        if(!root) return;\n        delNodesHelper(root->left, res, root, true);\n        delNodesHelper(root->right, res, root, false);\n        if(mmap.find(root->val) != mmap.end())\n        {\n            if(root->left) res.push_back(root->left);\n            if(root->right) res.push_back(root->right);\n            if(parent)\n            {\n                if(left) parent->left = NULL;\n                else parent->right = NULL;\n            }\n            delete root;\n        }\n        else if(!parent) res.push_back(root);\n    }\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n        for(int i = 0; i < to_delete.size(); i++)\n            mmap[to_delete[i]] = false;\n        vector<TreeNode*> res;\n        delNodesHelper(root, res, NULL, false);\n        return res;\n    }\n}; \n```\n Runtime Error Message: AddressSanitizer: heap-use-after-free on address 0x603000000588 at pc 0x000000471b5e bp 0x7ffe9ec14340 sp 0x7ffe9ec14338 \n Last executed input: [1,2,3,null,null,null,4]\n[2,1] \nThis works fine in Leetcode Playground.\n\nCan somebody please suggest what is going wrong here?
[]