Skip to content

Instantly share code, notes, and snippets.

@Aposhian
Created May 17, 2022 19:50
Show Gist options
  • Save Aposhian/91fc82d535b5910fcbfc456a630284b2 to your computer and use it in GitHub Desktop.
Save Aposhian/91fc82d535b5910fcbfc456a630284b2 to your computer and use it in GitHub Desktop.
double free on creating shared_ptr for member
#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