diff options
| author | Tom Lane | 2026-08-11 22:17:48 +0000 |
|---|---|---|
| committer | Tom Lane | 2026-08-11 22:17:48 +0000 |
| commit | 2e29cb3b815df71f02158dbe538ca7906291aa5c (patch) | |
| tree | 975556aaf19fba619a8249453a05ec6eabdb6326 | |
| parent | 6b3806732b7c5df06bdd0ed150e8a07b4ad62315 (diff) | |
Tweak allocation rule for tzload()'s "union local_storage" variable.
By default, allocate this via malloc, as we've been doing since commit
62c8421e8. Commit aeb07c55f adopted upstream tzdb's default of
allocating it on the stack, but that still doesn't seem like a good
idea for the reasons given in 62c8421e8 (and now memorialized in a
comment, in hopes that we don't make the same mistake again).
However, under USE_VALGRIND, put it on the stack as upstream does.
This accidentally prevents a crash when Python 3.14 is used under
Valgrind. The reasons for that are obscure, and it's most likely
not our bug, and even if we figured it out it'd be nice to have a fix
for buildfarm member skink now rather than after persuading the guilty
party to fix it.
In the normal non-USE_VALGRIND case, this has no effect on the logic
in released branches, and it reverts master to match them.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/f071e691-5930-4738-9dbd-43ed2da367fe@gmail.com
Backpatch-through: 14
| -rw-r--r-- | src/timezone/localtime.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index fa3c059038c..9af4fa142f4 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -583,17 +583,31 @@ tzloadbody(char const *name, char *canonname, struct state *sp, bool doextend, int tzload(const char *name, char *canonname, struct state *sp, bool doextend) { - union local_storage *lsp = malloc(sizeof *lsp); - + /* + * PG: by default, we allocate the "union local_storage" space via malloc, + * since it's about 70kB which seems like a lot of stack space, and we're + * hardly concerned about an extra malloc/free cycle here. But under + * USE_VALGRIND, put the variable on the stack, to intentionally increase + * the amount of stack space allocated in the postmaster. This prevents a + * bad interaction between Valgrind and Python 3.14, for reasons that are + * obscure and most likely no fault of ours. + */ + int r; + union local_storage *lsp; +#ifdef USE_VALGRIND + union local_storage ls; + + lsp = &ls; +#else + lsp = malloc(sizeof *lsp); if (!lsp) return errno; - else - { - int err = tzloadbody(name, canonname, sp, doextend, lsp); - - free(lsp); - return err; - } +#endif + r = tzloadbody(name, canonname, sp, doextend, lsp); +#ifndef USE_VALGRIND + free(lsp); +#endif + return r; } static bool |
