Skip to content

Commit e012423

Browse files
committed
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
1 parent 4335c95 commit e012423

File tree

1 file changed

+8
-7
lines changed
  • src/backend/storage/ipc

1 file changed

+8
-7
lines changed

src/backend/storage/ipc/dsm.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ dsm_attach(dsm_handle h)
566566
if (dsm_control->item[i].refcnt == 0)
567567
continue;
568568

569+
/* If the handle doesn't match, it's not the slot we want. */
570+
if (dsm_control->item[i].handle != seg->handle)
571+
continue;
572+
569573
/*
570574
* If the reference count is 1, the slot is still in use, but the
571575
* segment is in the process of going away. Treat that as if we
@@ -574,13 +578,10 @@ dsm_attach(dsm_handle h)
574578
if (dsm_control->item[i].refcnt == 1)
575579
break;
576580

577-
/* Otherwise, if the descriptor matches, we've found a match. */
578-
if (dsm_control->item[i].handle == seg->handle)
579-
{
580-
dsm_control->item[i].refcnt++;
581-
seg->control_slot = i;
582-
break;
583-
}
581+
/* Otherwise we've found a match. */
582+
dsm_control->item[i].refcnt++;
583+
seg->control_slot = i;
584+
break;
584585
}
585586
LWLockRelease(DynamicSharedMemoryControlLock);
586587

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy