Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in autowiring::signal #945

Merged
merged 1 commit into from May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/autowiring/signal.h
Expand Up @@ -118,6 +118,7 @@ namespace autowiring {
delete prior;
prior = cur;
}
delete prior;
}

signal& operator=(signal&& rhs) {
Expand Down
9 changes: 9 additions & 0 deletions src/autowiring/test/AutoSignalTest.cpp
Expand Up @@ -724,3 +724,12 @@ TEST_F(AutoSignalTest, IsExecuting) {
};
ASSERT_FALSE(sig.is_executing()) << "Signal was incorrectly marked as executing even though nothing is happening";
}

TEST_F(AutoSignalTest, NoLeaks) {
auto v = std::make_shared<bool>(false);
{
autowiring::signal<void()> x;
x += [v] {};
}
ASSERT_TRUE(v.unique()) << "Signal did not destroy all attached lambdas on its destruction";
}
11 changes: 10 additions & 1 deletion src/autowiring/test/OnceTest.cpp
Expand Up @@ -33,7 +33,7 @@ TEST(OnceTest, CallAfterSet) {
ASSERT_EQ(1, val2) << "Lambda not executed on assignment as expected";
}

TEST(OnceTest, NoLeaks) {
TEST(OnceTest, NoLeaks_Asserted) {
autowiring::once_signal<void> o;
auto v = std::make_shared<bool>(false);
o += [v] {};
Expand All @@ -45,6 +45,15 @@ TEST(OnceTest, NoLeaks) {
ASSERT_TRUE(v.unique()) << "Shared pointer leaked by once flag after post-set attachment";
}

TEST(OnceTest, NoLeaks_NotAsserted) {
auto v = std::make_shared<bool>(false);
{
autowiring::once_signal<void()> x;
x += [v] {};
}
ASSERT_TRUE(v.unique()) << "Signal did not destroy all attached lambdas on its destruction";
}

TEST(OnceTest, MultiLambdaPending) {
autowiring::once_signal<void> o;
std::atomic<int> x{ 0 };
Expand Down