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

Commit13492fc

Browse files
committed
Fix two violations of the ResourceOwnerEnlarge/Remember protocol.
The point of having separate ResourceOwnerEnlargeFoo andResourceOwnerRememberFoo functions is so that resource allocationcan happen in between. Doing it in some other order is just wrong.OpenTemporaryFile() did open(), enlarge, remember, which would leak theopen file if the enlarge step ran out of memory. Because fd.c has its ownlayer of resource-remembering, the consequences look like they'd be limitedto an intratransaction FD leak, but it's still not good.IncrBufferRefCount() did enlarge, remember, incr-refcount, which would blowup if the incr-refcount step ever failed. It was safe enough when written,but since the introduction of PrivateRefCountHash, I think the assumptionthat no error could happen there is pretty shaky.The odds of real problems from either bug are probably small, but still,back-patch to supported branches.Thomas Munro and Tom Lane, per a comment from Andres Freund
1 parent806fc52 commit13492fc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,11 +2630,11 @@ IncrBufferRefCount(Buffer buffer)
26302630
{
26312631
Assert(BufferIsPinned(buffer));
26322632
ResourceOwnerEnlargeBuffers(CurrentResourceOwner);
2633-
ResourceOwnerRememberBuffer(CurrentResourceOwner,buffer);
26342633
if (BufferIsLocal(buffer))
26352634
LocalRefCount[-buffer-1]++;
26362635
else
26372636
PrivateRefCount[buffer-1]++;
2637+
ResourceOwnerRememberBuffer(CurrentResourceOwner,buffer);
26382638
}
26392639

26402640
/*

‎src/backend/storage/file/fd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,13 @@ OpenTemporaryFile(bool interXact)
11941194
{
11951195
Filefile=0;
11961196

1197+
/*
1198+
* Make sure the current resource owner has space for this File before we
1199+
* open it, if we'll be registering it below.
1200+
*/
1201+
if (!interXact)
1202+
ResourceOwnerEnlargeFiles(CurrentResourceOwner);
1203+
11971204
/*
11981205
* If some temp tablespace(s) have been given to us, try to use the next
11991206
* one. If a given tablespace can't be found, we silently fall back to
@@ -1230,9 +1237,8 @@ OpenTemporaryFile(bool interXact)
12301237
{
12311238
VfdCache[file].fdstate |=FD_XACT_TEMPORARY;
12321239

1233-
ResourceOwnerEnlargeFiles(CurrentResourceOwner);
1234-
ResourceOwnerRememberFile(CurrentResourceOwner,file);
12351240
VfdCache[file].resowner=CurrentResourceOwner;
1241+
ResourceOwnerRememberFile(CurrentResourceOwner,file);
12361242

12371243
/* ensure cleanup happens at eoxact */
12381244
have_xact_temporary_files= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp