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

Commitbaa94eb

Browse files
committed
Avoid statically allocating gmtsub()'s timezone workspace.
localtime.c's "struct state" is a rather large object, ~23KB. We werestatically allocating one for gmtsub() to use to represent the GMTtimezone, even though that function is not at all heavily used and isnever reached in most backends. Let's malloc it on-demand, instead.This does pose the question of how to handle a malloc failure, butthere's already a well-defined error report convention here, ieset errno and return NULL.We have but one caller of pg_gmtime in HEAD, and two in back branches,neither of which were troubling to check for error. Make them do so.The possible errors are sufficiently unlikely (out-of-range timestamp,and now malloc failure) that I think elog() is adequate.Back-patch to all supported branches to keep our copies of the IANAtimezone code in sync. This particular change is in a stanza thatalready differs from upstream, so it's a wash for maintenance purposes--- but only as long as we keep the branches the same.Discussion:https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de
1 parent3a60c8b commitbaa94eb

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

‎src/backend/utils/adt/nabstime.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
113113
else
114114
tx=pg_gmtime(&time);
115115

116+
if (tx==NULL)
117+
elog(ERROR,"could not convert abstime to timestamp: %m");
118+
116119
tm->tm_year=tx->tm_year+1900;
117120
tm->tm_mon=tx->tm_mon+1;
118121
tm->tm_mday=tx->tm_mday;

‎src/backend/utils/adt/timestamp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,9 @@ GetEpochTime(struct pg_tm * tm)
18771877

18781878
t0=pg_gmtime(&epoch);
18791879

1880+
if (t0==NULL)
1881+
elog(ERROR,"could not convert epoch to timestamp: %m");
1882+
18801883
tm->tm_year=t0->tm_year;
18811884
tm->tm_mon=t0->tm_mon;
18821885
tm->tm_mday=t0->tm_mday;

‎src/timezone/localtime.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,13 +1328,14 @@ gmtsub(pg_time_t const *timep, int32 offset, struct pg_tm *tmp)
13281328
structpg_tm*result;
13291329

13301330
/* GMT timezone state data is kept here */
1331-
staticstructstategmtmem;
1332-
staticboolgmt_is_set= false;
1333-
#definegmtptr(&gmtmem)
1331+
staticstructstate*gmtptr=NULL;
13341332

1335-
if (!gmt_is_set)
1333+
if (gmtptr==NULL)
13361334
{
1337-
gmt_is_set= true;
1335+
/* Allocate on first use */
1336+
gmtptr= (structstate*)malloc(sizeof(structstate));
1337+
if (gmtptr==NULL)
1338+
returnNULL;/* errno should be set by malloc */
13381339
gmtload(gmtptr);
13391340
}
13401341
result=timesub(timep,offset,gmtptr,tmp);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp