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

Commit29ddb54

Browse files
committed
Fix inconsistent out-of-memory error reporting in dsa.c.
Commit16be2fd introduced the flag DSA_ALLOC_NO_OOM to control whetherthe DSA allocator would raise an error or return InvalidDsaPointer onfailure to allocate. One edge case was not handled correctly: if wefail to allocate an internal "span" object for a large allocation, wewould always return InvalidDsaPointer regardless of the flag; a callernot expecting that could then dereference a null pointer.This is a plausible explanation for a one-off report of a segfault.Remove a redundant pair of braces so that all three stanzas that handleDSA_ALLOC_NO_OOM match in style, for visual consistency.While fixing inconsistencies, if FreePageManagerGet() can't supply thepages that our book-keeping says it should be able to supply, then weshould always report a FATAL error. Previously we treated that as aregular allocation failure in one code path, but as a FATAL conditionin another.Back-patch to 10, where dsa.c landed.Author: Thomas MunroReported-by: Jakub GlapaDiscussion:https://postgr.es/m/CAEepm=2oPqXxyWQ-1o60tpOLrwkw=VpgNXqqF1VN2EyO9zKGQw@mail.gmail.com
1 parent9e138a4 commit29ddb54

File tree

1 file changed

+16
-8
lines changed
  • src/backend/utils/mmgr

1 file changed

+16
-8
lines changed

‎src/backend/utils/mmgr/dsa.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,16 @@ dsa_allocate_extended(dsa_area *area, size_t size, int flags)
693693
/* Obtain a span object. */
694694
span_pointer=alloc_object(area,DSA_SCLASS_BLOCK_OF_SPANS);
695695
if (!DsaPointerIsValid(span_pointer))
696+
{
697+
/* Raise error unless asked not to. */
698+
if ((flags&DSA_ALLOC_NO_OOM)==0)
699+
ereport(ERROR,
700+
(errcode(ERRCODE_OUT_OF_MEMORY),
701+
errmsg("out of memory"),
702+
errdetail("Failed on DSA request of size %zu.",
703+
size)));
696704
returnInvalidDsaPointer;
705+
}
697706

698707
LWLockAcquire(DSA_AREA_LOCK(area),LW_EXCLUSIVE);
699708

@@ -790,12 +799,10 @@ dsa_allocate_extended(dsa_area *area, size_t size, int flags)
790799
{
791800
/* Raise error unless asked not to. */
792801
if ((flags&DSA_ALLOC_NO_OOM)==0)
793-
{
794802
ereport(ERROR,
795803
(errcode(ERRCODE_OUT_OF_MEMORY),
796804
errmsg("out of memory"),
797805
errdetail("Failed on DSA request of size %zu.",size)));
798-
}
799806
returnInvalidDsaPointer;
800807
}
801808

@@ -1669,13 +1676,14 @@ ensure_active_superblock(dsa_area *area, dsa_area_pool *pool,
16691676
return false;
16701677
}
16711678
}
1679+
/*
1680+
* This shouldn't happen: get_best_segment() or make_new_segment()
1681+
* promised that we can successfully allocate npages.
1682+
*/
16721683
if (!FreePageManagerGet(segment_map->fpm,npages,&first_page))
1673-
{
1674-
LWLockRelease(DSA_AREA_LOCK(area));
1675-
if (size_class!=DSA_SCLASS_BLOCK_OF_SPANS)
1676-
dsa_free(area,span_pointer);
1677-
return false;
1678-
}
1684+
elog(FATAL,
1685+
"dsa_allocate could not find %zu free pages for superblock",
1686+
npages);
16791687
LWLockRelease(DSA_AREA_LOCK(area));
16801688

16811689
/* Compute the start of the superblock. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp