From fcbf455842eac10c331a866f559bb3875bcb8c37 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Thu, 13 Aug 2015 00:12:07 -0300 Subject: [PATCH] Fix unitialized variables As complained by clang, reported by Andres Freund. Brown paper bag bug in ccc4c074994d. Add some comments, too. Backpatch to 9.5, like that one. --- src/backend/access/brin/brin_pageops.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/backend/access/brin/brin_pageops.c b/src/backend/access/brin/brin_pageops.c index 875544e336..6a2fd474d9 100644 --- a/src/backend/access/brin/brin_pageops.c +++ b/src/backend/access/brin/brin_pageops.c @@ -86,6 +86,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, { LockBuffer(oldbuf, BUFFER_LOCK_EXCLUSIVE); newbuf = InvalidBuffer; + extended = false; } oldpage = BufferGetPage(oldbuf); oldlp = PageGetItemId(oldpage, oldoff); @@ -335,9 +336,8 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, brinRevmapExtend(revmap, heapBlk); /* - * Obtain a locked buffer to insert the new tuple. Note - * brin_getinsertbuffer ensures there's enough space in the returned - * buffer. + * Acquire lock on buffer supplied by caller, if any. If it doesn't have + * enough space, unpin it to obtain a new one below. */ if (BufferIsValid(*buffer)) { @@ -354,12 +354,18 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, } } + /* + * If we still don't have a usable buffer, have brin_getinsertbuffer + * obtain one for us. + */ if (!BufferIsValid(*buffer)) { *buffer = brin_getinsertbuffer(idxrel, InvalidBuffer, itemsz, &extended); Assert(BufferIsValid(*buffer)); Assert(extended || br_page_get_freespace(BufferGetPage(*buffer)) >= itemsz); } + else + extended = false; /* Now obtain lock on revmap buffer */ revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk); @@ -367,6 +373,7 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, page = BufferGetPage(*buffer); blk = BufferGetBlockNumber(*buffer); + /* Execute the actual insertion */ START_CRIT_SECTION(); if (extended) brin_page_init(BufferGetPage(*buffer), BRIN_PAGETYPE_REGULAR); -- 2.40.0