Created
May 17, 2022 19:50
-
-
Save Aposhian/91fc82d535b5910fcbfc456a630284b2 to your computer and use it in GitHub Desktop.
double free on creating shared_ptr for member
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
class Outside; | |
class Inside { | |
public: | |
Inside(std::shared_ptr<Outside> outside): outside_(outside) {} | |
std::shared_ptr<Outside> outside_; | |
}; | |
class Outside { | |
public: | |
Outside(): inside_( | |
std::move( | |
std::make_unique<Inside>( | |
std::shared_ptr<Outside>(this) | |
) | |
) | |
) {} | |
std::unique_ptr<Inside> inside_; | |
}; | |
int main() { | |
auto outside = std::make_shared<Outside>(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment