Skip to content

Commit b4573d3

Browse files
author
Artyom Abakumov
committed
Fix segfault at engine unit tests cleanup stage
1 parent 309fefa commit b4573d3

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

src/jrd/tests/TestContext.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,30 @@ class CachedAttach
3535
return att;
3636
}
3737

38-
~CachedAttach()
38+
void removeDb()
3939
{
40+
if (std::filesystem::exists(dbPath))
41+
std::filesystem::remove(dbPath);
42+
}
43+
44+
45+
void shutdown()
46+
{
47+
if (att == nullptr)
48+
return;
49+
4050
att->release();
51+
att = nullptr;
4152
Jrd::TraceManager::getStorage()->shutdown();
4253
removeDb();
4354
}
4455

45-
void removeDb()
56+
~CachedAttach()
4657
{
47-
if (std::filesystem::exists(dbPath))
48-
std::filesystem::remove(dbPath);
58+
shutdown();
4959
}
5060

61+
5162
Jrd::JProvider prov{nullptr};
5263
Firebird::FbLocalStatus status;
5364

@@ -60,6 +71,20 @@ class CachedAttach
6071
};
6172
static Firebird::GlobalPtr<CachedAttach, Firebird::InstanceControl::PRIORITY_DELETE_FIRST> storage;
6273

74+
// Cleanp of the cached attachment must be done before global FB cleanp or a pool-related segfault will be present
75+
class TestsCleanCallback
76+
{
77+
public:
78+
TestsCleanCallback()
79+
{ }
80+
81+
~TestsCleanCallback()
82+
{
83+
storage->shutdown();
84+
}
85+
};
86+
87+
BOOST_TEST_GLOBAL_FIXTURE(TestsCleanCallback);
6388

6489
TestContextHolder::TestContextHolder() :
6590
m_tdbb(&storage->status, storage->getAttachment(), FB_FUNCTION),

0 commit comments

Comments
 (0)