Thread: RemoveLocalLock pfree'ing NULL when out-of-memory

RemoveLocalLock pfree'ing NULL when out-of-memory

From
Andreas Seltenreich
Date:
Hi,

a memory-starved instance of sqlsmith just caught RemoveLocalLock
pfree'ing a NULL in locallock->lockOwners.  I think what happened is
that it was called to clean up after LockAcquireExtended's
MemoryContextAlloc failed.  The content of errordata seems consistent
with this.

Caught in master as of 85eda7e (sorry about the bogus hashes in earlier
reports, I had some cruft on my local branch).

regards,
Andreas

FailedAssertion("!(pointer != ((void *)0))", File: "mcxt.c", Line: 1002)

#3  0x00000000007e1c80 in pfree (pointer=<optimized out>) at mcxt.c:1002
#4  0x00000000006bdd24 in RemoveLocalLock (locallock=locallock@entry=0x3a90d68) at lock.c:1225
#5  0x00000000006c1ceb in LockReleaseAll (lockmethodid=lockmethodid@entry=1, allLocks=1 '\001') at lock.c:2083
#6  0x00000000006c3274 in ProcReleaseLocks (isCommit=isCommit@entry=0 '\000') at proc.c:752
#7  0x00000000007e3700 in ResourceOwnerReleaseInternal (owner=owner@entry=0x208b488,
phase=phase@entry=RESOURCE_RELEASE_LOCKS,   isCommit=isCommit@entry=0 '\000', isTopLevel=isTopLevel@entry=1 '\001') at
resowner.c:307
#8  0x00000000007e381f in ResourceOwnerRelease (owner=0x208b488, phase=phase@entry=RESOURCE_RELEASE_LOCKS,
isCommit=isCommit@entry=0'\000', isTopLevel=isTopLevel@entry=1 '\001') at resowner.c:212
 
#9  0x00000000004e903b in AbortTransaction () at xact.c:2557
#10 0x00000000004e98ad in AbortCurrentTransaction () at xact.c:3003
#11 0x00000000006d45a3 in PostgresMain (argc=1, argv=0x202e638, dbname=0x202e610 "regression", username=0x202e5f0
"smith")  at postgres.c:3856
 
#12 0x0000000000466964 in BackendRun (port=0x204e080) at postmaster.c:4204
#13 BackendStartup (port=0x204e080) at postmaster.c:3880
#14 ServerLoop () at postmaster.c:1683
#15 0x000000000067867e in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x202d600) at postmaster.c:1292
#16 0x000000000046774d in main (argc=3, argv=0x202d600) at main.c:223

(gdb) p errordata[0]
$4 = {elevel = 20, output_to_server = 0 '\000', output_to_client = 1 '\001', show_funcname = 0 '\000', hide_stmt = 0
'\000', hide_ctx = 0 '\000', filename = 0x9a1f80 "mcxt.c", lineno = 769, funcname = 0x9a24b0 <__func__.5880>
"MemoryContextAlloc", domain = 0x9350f6 "postgres-9.6", context_domain = 0x9350f6 "postgres-9.6", sqlerrcode = 8389,
message= 0x296d020 "out of memory", detail = 0x296cfe8 "Failed on request of size 128.", detail_log = 0x0, hint = 0x0,
context= 0x0, schema_name = 0x0, table_name = 0x0, column_name = 0x0, datatype_name = 0x0, constraint_name = 0x0,
cursorpos= 0,  internalpos = 0, internalquery = 0x0, saved_errno = 12, assoc_context = 0x296a7a8}
 



Re: RemoveLocalLock pfree'ing NULL when out-of-memory

From
Tom Lane
Date:
Andreas Seltenreich <seltenreich@gmx.de> writes:
> a memory-starved instance of sqlsmith just caught RemoveLocalLock
> pfree'ing a NULL in locallock->lockOwners.  I think what happened is
> that it was called to clean up after LockAcquireExtended's
> MemoryContextAlloc failed.  The content of errordata seems consistent
> with this.

Ooops.  Looks to have been my bug originally.  Will fix, thanks!
        regards, tom lane