8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:03:03 +01:00

Fixed bug #8150 : Process could attach to the deleted instance of shared memory

Patch and additional comments by @AlexPeshkoff
This commit is contained in:
Vlad Khorsun 2024-06-05 21:34:29 +03:00
parent 0220cd109c
commit 07d09c3252
2 changed files with 16 additions and 3 deletions

View File

@ -1127,13 +1127,17 @@ void SharedMemoryBase::removeMapFile()
if (!sh_mem_header->isDeleted())
{
#ifndef WIN_NT
unlinkFile();
FileLockHolder initLock(initFile);
if (!sh_mem_header->isDeleted())
{
unlinkFile();
sh_mem_header->markAsDeleted();
}
#else
fb_assert(!sh_mem_unlink);
sh_mem_unlink = true;
#endif // WIN_NT
sh_mem_header->markAsDeleted();
#endif // WIN_NT
}
}

View File

@ -385,6 +385,10 @@ TipCache::StatusBlockData::StatusBlockData(thread_db* tdbb, TipCache* tipCache,
try
{
// Here SharedMemory constructor is called with skipLock parameter set to true.
// Appropriate locking is performed by existenceLock using LM.
// This should be in sync with SharedMemoryBase::unlinkFile() call
// in TipCache::StatusBlockData::clear().
memory = FB_NEW_POOL(*dbb->dbb_permanent) SharedMemory<TransactionStatusBlock>(
fileName.c_str(), blockSize,
&cache->memBlockInitializer, true);
@ -462,6 +466,11 @@ void TipCache::StatusBlockData::clear(thread_db* tdbb)
if (fName.hasData())
{
// Here file is removed from SharedMemory created with skipLock parameter
// set to true. That means internal file lock is turned off.
// Appropriate locking is performed by existenceLock using LM.
// This should be in sync with SharedMemory constructor called
// in TipCache::StatusBlockData constructor.
if (LCK_lock(tdbb, &existenceLock, LCK_EX, LCK_NO_WAIT))
SharedMemoryBase::unlinkFile(fName.c_str());
else