mirror of
https://github.com/postgres/postgres.git
synced 2025-06-10 00:01:28 -04:00
Fix logic bug in dsm_attach().
The previous coding would potentially cause attaching to segment A to fail if segment B was at the same time in the process of going away. Andres Freund, with a comment tweak by me
This commit is contained in:
parent
4335c95815
commit
e0124230ba
@ -566,6 +566,10 @@ dsm_attach(dsm_handle h)
|
|||||||
if (dsm_control->item[i].refcnt == 0)
|
if (dsm_control->item[i].refcnt == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* If the handle doesn't match, it's not the slot we want. */
|
||||||
|
if (dsm_control->item[i].handle != seg->handle)
|
||||||
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the reference count is 1, the slot is still in use, but the
|
* If the reference count is 1, the slot is still in use, but the
|
||||||
* segment is in the process of going away. Treat that as if we
|
* segment is in the process of going away. Treat that as if we
|
||||||
@ -574,14 +578,11 @@ dsm_attach(dsm_handle h)
|
|||||||
if (dsm_control->item[i].refcnt == 1)
|
if (dsm_control->item[i].refcnt == 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Otherwise, if the descriptor matches, we've found a match. */
|
/* Otherwise we've found a match. */
|
||||||
if (dsm_control->item[i].handle == seg->handle)
|
|
||||||
{
|
|
||||||
dsm_control->item[i].refcnt++;
|
dsm_control->item[i].refcnt++;
|
||||||
seg->control_slot = i;
|
seg->control_slot = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
LWLockRelease(DynamicSharedMemoryControlLock);
|
LWLockRelease(DynamicSharedMemoryControlLock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user