postgres.git / summary / log / commit / refs

commit    059f30c1b1afe861aa9541feb970494db05a1d2e
Author:   Andres Freund <andres@anarazel.de>
Date:     Thu Jan 29 16:49:03 2015 +0000
First released in: 9.5.0, 9.0.19, 9.1.15, 9.2.10, 9.3.6, 9.4.1

    Properly terminate the array returned by GetLockConflicts().
    
    GetLockConflicts() has for a long time not properly terminated the
    returned array. During normal processing the returned array is zero
    initialized which, while not pretty, is sufficient to be recognized as
    a invalid virtual transaction id. But the HotStandby case is more than
    aesthetically broken: The allocated (and reused) array is neither
    zeroed upon allocation, nor reinitialized, nor terminated.
    
    Not having a terminating element means that the end of the array will
    not be recognized and that recovery conflict handling will thus read
    ahead into adjacent memory. Only terminating when hitting memory
    content that looks like a invalid virtual transaction id.  Luckily
    this seems so far not have caused significant problems, besides making
    recovery conflict more expensive.
    
    Discussion: 20150127142713.GD29457@awork2.anarazel.de
    
    Backpatch into all supported branches.


src/backend/storage/lmgr/lock.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 02245bbfd98..8b5dcb82a81 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -1944,6 +1944,8 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) * on this lockable object. */ LWLockRelease(partitionLock); + vxids[count].backendId = InvalidBackendId; + vxids[count].localTransactionId = InvalidLocalTransactionId; return vxids; } @@ -1989,6 +1991,8 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) if (count > MaxBackends) /* should never happen */ elog(PANIC, "too many conflicting locks found"); + vxids[count].backendId = InvalidBackendId; + vxids[count].localTransactionId = InvalidLocalTransactionId; return vxids; } [parent: 3a20633694c1]