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

Commit 66102d0

Browse files
tglsfdcCommitfest Bot
authored and
Commitfest Bot
committed
Harden brininsertcleanup against repeat calls.
Leaving an empty BrinInsertState struct linked in ii_AmCache confuses both brininsertcleanup itself and brininsert, were that to be called again. We should fully remove it, instead. This stops the crash reported in bug #18815. I think it's fixing the symptom rather than the root cause, but nonetheless there's little argument for brininsertcleanup to be leaving an obviously broken data structure behind. Bug: #18815 Reported-by: Sergey Belyashov <sergey.belyashov@gmail.com> Discussion: https://postgr.es/m/18815-2a0407cc7f40b327@postgresql.org Backpatch-through: TBD
1 parent 9296ccf commit 66102d0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/access/brin/brin.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,18 @@ brininsertcleanup(Relation index, IndexInfo *indexInfo)
511511
BrinInsertState *bistate = (BrinInsertState *) indexInfo->ii_AmCache;
512512

513513
/* bail out if cache not initialized */
514-
if (indexInfo->ii_AmCache == NULL)
514+
if (bistate == NULL)
515515
return;
516516

517+
/* do this first to avoid dangling pointer if we fail partway through */
518+
indexInfo->ii_AmCache = NULL;
519+
517520
/*
518521
* Clean up the revmap. Note that the brinDesc has already been cleaned up
519522
* as part of its own memory context.
520523
*/
521524
brinRevmapTerminate(bistate->bis_rmAccess);
522-
bistate->bis_rmAccess = NULL;
523-
bistate->bis_desc = NULL;
525+
pfree(bistate);
524526
}
525527

526528
/*

0 commit comments

Comments
 (0)