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

Commitc5c87f0

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 parentca4ac3f commitc5c87f0

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
@@ -238,39 +238,47 @@ LargeObjectDesc *
238238
inv_open(OidlobjId,intflags,MemoryContextmcxt)
239239
{
240240
LargeObjectDesc*retval;
241-
242-
retval= (LargeObjectDesc*)MemoryContextAlloc(mcxt,
243-
sizeof(LargeObjectDesc));
244-
245-
retval->id=lobjId;
246-
retval->subid=GetCurrentSubTransactionId();
247-
retval->offset=0;
241+
Snapshotsnapshot=NULL;
242+
intdescflags=0;
248243

249244
if (flags&INV_WRITE)
250245
{
251-
retval->snapshot=SnapshotNow;
252-
retval->flags=IFS_WRLOCK |IFS_RDLOCK;
246+
snapshot=SnapshotNow;
247+
descflags=IFS_WRLOCK |IFS_RDLOCK;
253248
}
254249
elseif (flags&INV_READ)
255250
{
256-
/*
257-
* We must register the snapshot in TopTransaction's resowner, because
258-
* it must stay alive until the LO is closed rather than until the
259-
* current portal shuts down.
260-
*/
261-
retval->snapshot=RegisterSnapshotOnOwner(GetActiveSnapshot(),
262-
TopTransactionResourceOwner);
263-
retval->flags=IFS_RDLOCK;
251+
snapshot=GetActiveSnapshot();
252+
descflags=IFS_RDLOCK;
264253
}
265254
else
266255
elog(ERROR,"invalid flags: %d",flags);
267256

268257
/* Can't use LargeObjectExists here because it always uses SnapshotNow */
269-
if (!myLargeObjectExists(lobjId,retval->snapshot))
258+
if (!myLargeObjectExists(lobjId,snapshot))
270259
ereport(ERROR,
271260
(errcode(ERRCODE_UNDEFINED_OBJECT),
272261
errmsg("large object %u does not exist",lobjId)));
273262

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp