Skip to content

Commit 75cfe64

Browse files
Attempt to resolve a valgrind issue (CppMicroServices#1066) (CppMicroServices#1188)
trying to resolve this valgrind reported issue: 26: ==24460== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) 26: ==24460== by 0x40147D9: calloc (rtld-malloc.h:44) 26: ==24460== by 0x40147D9: allocate_dtv (dl-tls.c:375) 26: ==24460== by 0x40147D9: _dl_allocate_tls (dl-tls.c:634) 26: ==24460== by 0x4E5B7B4: allocate_stack (allocatestack.c:430) 26: ==24460== by 0x4E5B7B4: pthread_create@@GLIBC_2.34 (pthread_create.c:647) 26: ==24460== by 0x91D5EE: boost::asio::thread_pool::thread_pool(unsigned long) (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/bin/usDeclarativeServicesTests) 26: ==24460== by 0x916EDF: test::AsyncWorkServiceThreadPool::AsyncWorkServiceThreadPool(int) (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/bin/usDeclarativeServicesTests) 26: ==24460== by 0x53FCF9: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<test::AsyncWorkServiceThreadPool, std::allocator<test::AsyncWorkServiceThreadPool>, int>(test::AsyncWorkServiceThreadPool*&, std::_Sp_alloc_shared_tag<std::allocator<test::AsyncWorkServiceThreadPool> >, int&&) (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/bin/usDeclarativeServicesTests) 26: ==24460== by 0x52906B: test::TestAsyncWorkServiceEndToEnd_testUpdateConfigFromWithinModifiedCallback_Test::TestBody() (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/bin/usDeclarativeServicesTests) 26: ==24460== by 0x491AEC0: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/lib/libgtest.so.1.14.0) 26: ==24460== by 0x48FB4E5: testing::Test::Run() (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/lib/libgtest.so.1.14.0) 26: ==24460== by 0x48FB6A4: testing::TestInfo::Run() (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/lib/libgtest.so.1.14.0) 26: ==24460== by 0x48FB868: testing::TestSuite::Run() (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/lib/libgtest.so.1.14.0) 26: ==24460== by 0x491015E: testing::internal::UnitTestImpl::RunAllTests() (in /home/runner/work/CppMicroServices/CppMicroServices/build_0/lib/libgtest.so.1.14.0) Signed-off-by: The MathWorks, Inc. <jdicleme@mathworks.com> Co-authored-by: Jeff DiClemente <jeffdiclemente@users.noreply.github.com>
1 parent 92e3c8c commit 75cfe64

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

compendium/DeclarativeServices/test/TestUtils.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,23 +281,11 @@ namespace test
281281

282282
AsyncWorkServiceThreadPool::~AsyncWorkServiceThreadPool()
283283
{
284-
try
285-
{
286-
if (threadpool)
287-
{
288-
try
289-
{
290-
threadpool->join();
291-
}
292-
catch (...)
293-
{
294-
//
295-
}
296-
}
297-
}
298-
catch (...)
284+
if (threadpool)
299285
{
300-
//
286+
threadpool->join();
287+
threadpool->stop();
288+
threadpool.reset();
301289
}
302290
}
303291

compendium/DeclarativeServices/test/TestUtils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ namespace test
107107
*/
108108
bool isBundleLoadedInThisProcess(std::string bundleName);
109109

110+
/**
111+
* Implementation of AsyncWorkService that uses a boost::asio::thread_pool
112+
* to execute asynchronous tasks.
113+
*/
110114
class AsyncWorkServiceThreadPool : public cppmicroservices::async::AsyncWorkService
111115
{
112116
public:

compendium/DeclarativeServices/test/gtest/TestAsyncWorkService.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ namespace test
432432

433433
// ASYNCWORKSERVICE
434434
auto reg = context.RegisterService<cppmicroservices::async::AsyncWorkService>(param);
435-
US_UNUSED(reg);
436435

437436
// CA
438437
::test::InstallAndStartConfigAdmin(context);
@@ -466,6 +465,8 @@ namespace test
466465
auto serviceRef = context.GetServiceReference<test::CAInterface>();
467466
auto service = context.GetService<test::CAInterface>(serviceRef);
468467
ASSERT_TRUE(service) << "GetService failed for CAInterface";
468+
469+
ASSERT_NO_THROW(reg.Unregister());
469470
}
470471

471472
}; // namespace test

0 commit comments

Comments
 (0)