Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit357f752

Browse files
committed
Fix snapshot leak if lo_open called on non-existent object.
lo_open registers the currently active snapshot, and checks if thelarge object exists after that. Normally, snapshots registered by lo_openare unregistered at end of transaction when the lo descriptor is closed, butif we error out before the lo descriptor is added to the list of opendescriptors, it is leaked. Fix by moving the snapshot registration to afterchecking if the large object exists.Reported by Pavel Stehule. Backpatch to 8.4. The snapshot registrationsystem was introduced in 8.4, so prior versions are not affected (and notsupported, anyway).
1 parent514b319 commit357f752

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

‎src/backend/storage/large_object/inv_api.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,29 +240,18 @@ LargeObjectDesc *
240240
inv_open(OidlobjId,intflags,MemoryContextmcxt)
241241
{
242242
LargeObjectDesc*retval;
243-
244-
retval= (LargeObjectDesc*)MemoryContextAlloc(mcxt,
245-
sizeof(LargeObjectDesc));
246-
247-
retval->id=lobjId;
248-
retval->subid=GetCurrentSubTransactionId();
249-
retval->offset=0;
243+
Snapshotsnapshot=NULL;
244+
intdescflags=0;
250245

251246
if (flags&INV_WRITE)
252247
{
253-
retval->snapshot=NULL;/* instantaneous MVCC snapshot */
254-
retval->flags=IFS_WRLOCK |IFS_RDLOCK;
248+
snapshot=NULL;/* instantaneous MVCC snapshot */
249+
descflags=IFS_WRLOCK |IFS_RDLOCK;
255250
}
256251
elseif (flags&INV_READ)
257252
{
258-
/*
259-
* We must register the snapshot in TopTransaction's resowner, because
260-
* it must stay alive until the LO is closed rather than until the
261-
* current portal shuts down.
262-
*/
263-
retval->snapshot=RegisterSnapshotOnOwner(GetActiveSnapshot(),
264-
TopTransactionResourceOwner);
265-
retval->flags=IFS_RDLOCK;
253+
snapshot=GetActiveSnapshot();
254+
descflags=IFS_RDLOCK;
266255
}
267256
else
268257
ereport(ERROR,
@@ -271,11 +260,30 @@ inv_open(Oid lobjId, int flags, MemoryContext mcxt)
271260
flags)));
272261

273262
/* Can't use LargeObjectExists here because we need to specify snapshot */
274-
if (!myLargeObjectExists(lobjId,retval->snapshot))
263+
if (!myLargeObjectExists(lobjId,snapshot))
275264
ereport(ERROR,
276265
(errcode(ERRCODE_UNDEFINED_OBJECT),
277266
errmsg("large object %u does not exist",lobjId)));
278267

268+
/*
269+
* We must register the snapshot in TopTransaction's resowner, because
270+
* it must stay alive until the LO is closed rather than until the
271+
* current portal shuts down. Do this after checking that the LO exists,
272+
* to avoid leaking the snapshot if an error is thrown.
273+
*/
274+
if (snapshot)
275+
snapshot=RegisterSnapshotOnOwner(snapshot,
276+
TopTransactionResourceOwner);
277+
278+
/* All set, create a descriptor */
279+
retval= (LargeObjectDesc*)MemoryContextAlloc(mcxt,
280+
sizeof(LargeObjectDesc));
281+
retval->id=lobjId;
282+
retval->subid=GetCurrentSubTransactionId();
283+
retval->offset=0;
284+
retval->snapshot=snapshot;
285+
retval->flags=descflags;
286+
279287
returnretval;
280288
}
281289

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp