Skip to content

Commit 1f488a5

Browse files
Resolve valgrind 'possibly lost' leaks (CppMicroServices#1067) (CppMicroServices#1179)
* Update valgrind_suppressions.txt add a general suppression to ignore pthread tls allocation. Through investigation this memory flagged as possibly lost by valgrind appears to be a culmination of how pthread manages allocating TLS memory and repeatedly creating/joining and destroying std::thread objects in the test process. Signed-off-by: The MathWorks, Inc. <jdicleme@mathworks.com> Co-authored-by: Jeff DiClemente <jeffdiclemente@users.noreply.github.com>
1 parent 3b65270 commit 1f488a5

3 files changed

Lines changed: 21 additions & 331 deletions

File tree

framework/src/util/FrameworkPrivate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ namespace cppmicroservices
5353
stopEvent = FrameworkEventInternal { true, FrameworkEvent::Type::FRAMEWORK_ERROR, std::string(), nullptr };
5454
}
5555

56+
FrameworkPrivate::~FrameworkPrivate() noexcept
57+
{
58+
if (shutdownThread.joinable())
59+
{
60+
shutdownThread.join();
61+
}
62+
}
63+
5664
void
5765
FrameworkPrivate::DoInit()
5866
{
@@ -121,6 +129,10 @@ namespace cppmicroservices
121129
}
122130
if (!stopEvent.valid)
123131
{
132+
if (shutdownThread.joinable())
133+
{
134+
shutdownThread.join();
135+
}
124136
return FrameworkEvent(FrameworkEvent::Type::FRAMEWORK_WAIT_TIMEDOUT,
125137
MakeBundle(this->shared_from_this()),
126138
std::string(),

framework/src/util/FrameworkPrivate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace cppmicroservices
4444
{
4545
public:
4646
FrameworkPrivate(CoreBundleContext* fwCtx);
47+
~FrameworkPrivate() noexcept override;
4748

4849
void Init();
4950

@@ -113,12 +114,12 @@ namespace cppmicroservices
113114
*/
114115
void SystemShuttingdownDone_unlocked(FrameworkEventInternal const& fe);
115116

117+
private:
116118
/**
117119
* The thread that performs shutdown of this framework instance.
118120
*/
119121
std::thread shutdownThread;
120122

121-
private:
122123
AnyMap headers;
123124
};
124125
} // namespace cppmicroservices

0 commit comments

Comments
 (0)