allocate-gmtmem-only-when-needed.patch
text/x-diff
Filename: allocate-gmtmem-only-when-needed.patch
Type: text/x-diff
Part: 0
Message:
Re: Large writable variables
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/utils/adt/timestamp.c | 0 | 0 |
| src/timezone/localtime.c | 0 | 0 |
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index ba15a29..449164a 100644
*** a/src/backend/utils/adt/timestamp.c
--- b/src/backend/utils/adt/timestamp.c
*************** GetEpochTime(struct pg_tm *tm)
*** 2008,2013 ****
--- 2008,2016 ----
t0 = pg_gmtime(&epoch);
+ if (t0 == NULL)
+ elog(ERROR, "could not convert epoch to timestamp: %m");
+
tm->tm_year = t0->tm_year;
tm->tm_mon = t0->tm_mon;
tm->tm_mday = t0->tm_mday;
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c
index 31b06b0..04a1013 100644
*** a/src/timezone/localtime.c
--- b/src/timezone/localtime.c
*************** gmtsub(pg_time_t const *timep, int32 off
*** 1328,1340 ****
struct pg_tm *result;
/* GMT timezone state data is kept here */
! static struct state gmtmem;
! static bool gmt_is_set = false;
! #define gmtptr (&gmtmem)
! if (!gmt_is_set)
{
! gmt_is_set = true;
gmtload(gmtptr);
}
result = timesub(timep, offset, gmtptr, tmp);
--- 1328,1341 ----
struct pg_tm *result;
/* GMT timezone state data is kept here */
! static struct state *gmtptr = NULL;
! if (gmtptr == NULL)
{
! /* Allocate on first use. */
! gmtptr = (struct state *) malloc(sizeof(struct state));
! if (gmtptr == NULL)
! return NULL; /* errno should be set by malloc */
gmtload(gmtptr);
}
result = timesub(timep, offset, gmtptr, tmp);