1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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
This commit is contained in:
Tom Lane
2026-08-11 18:17:48 -04:00
parent bc86dc738e
commit 040932c311

View File

@@ -617,12 +617,32 @@ tzloadbody(char const *name, char *canonname,
static int
tzload(char const *name, char *canonname, struct state *sp, char tzloadflags)
{
/* PG: our version of tzloadbody never reallocates *lspp */
/*
* 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. Also note that unlike
* upstream tzcode, our version of tzloadbody never reallocates *lspp.
*/
int r;
union local_storage *lsp;
#ifdef USE_VALGRIND
union local_storage ls;
lsp = &ls;
return tzloadbody(name, canonname, sp, tzloadflags, &lsp);
#else
lsp = malloc(sizeof *lsp);
if (!lsp)
return errno;
#endif
r = tzloadbody(name, canonname, sp, tzloadflags, &lsp);
#ifndef USE_VALGRIND
free(lsp);
#endif
return r;
}
static const int mon_lengths[2][MONSPERYEAR] = {