Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4ab7769

Browse files
author
Amit Kapila
committed
Fix the SharedFileSetUnregister API.
Commit 808e13b introduced a few APIs to extend the existing Buffile interface. In SharedFileSetDeleteOnProcExit, it tries to delete the list element while traversing the list with 'foreach' construct which makes the behavior of list traversal unpredictable. Author: Amit Kapila Reviewed-by: Dilip Kumar Tested-by: Dilip Kumar and Neha Sharma Discussion: https://postgr.es/m/CAA4eK1JhLatVcQ2OvwA_3s0ih6Hx9+kZbq107cXVsSWWukH7vA@mail.gmail.com
1 parent ab3c6d4 commit 4ab7769

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/storage/file/sharedfileset.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,16 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum)
266266
static void
267267
SharedFileSetDeleteOnProcExit(int status, Datum arg)
268268
{
269-
ListCell *l;
270-
271-
/* Loop over all the pending shared fileset entry */
272-
foreach(l, filesetlist)
269+
/*
270+
* Remove all the pending shared fileset entries. We don't use foreach() here
271+
* because SharedFileSetDeleteAll will remove the current element in
272+
* filesetlist. Though we have used foreach_delete_current() to remove the
273+
* element from filesetlist it could only fix up the state of one of the
274+
* loops, see SharedFileSetUnregister.
275+
*/
276+
while (list_length(filesetlist) > 0)
273277
{
274-
SharedFileSet *fileset = (SharedFileSet *) lfirst(l);
278+
SharedFileSet *fileset = (SharedFileSet *) linitial(filesetlist);
275279

276280
SharedFileSetDeleteAll(fileset);
277281
}
@@ -301,7 +305,7 @@ SharedFileSetUnregister(SharedFileSet *input_fileset)
301305
/* Remove the entry from the list */
302306
if (input_fileset == fileset)
303307
{
304-
filesetlist = list_delete_cell(filesetlist, l);
308+
filesetlist = foreach_delete_current(filesetlist, l);
305309
return;
306310
}
307311
}

0 commit comments

Comments
 (0)