mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Modify hash_search() API to prevent future occurrences of the error
spotted by Qingqing Zhou. The HASH_ENTER action now automatically fails with elog(ERROR) on out-of-memory --- which incidentally lets us eliminate duplicate error checks in quite a bunch of places. If you really need the old return-NULL-on-out-of-memory behavior, you can ask for HASH_ENTER_NULL. But there is now an Assert in that path checking that you aren't hoping to get that behavior in a palloc-based hash table. Along the way, remove the old HASH_FIND_SAVE/HASH_REMOVE_SAVED actions, which were not being used anywhere anymore, and were surely too ugly and unsafe to want to see revived again.
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.31 2005/05/23 21:54:02 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.32 2005/05/29 04:23:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -971,6 +971,7 @@ identify_system_timezone(void)
|
||||
* load and parse the TZ definition file every time it is selected.
|
||||
*/
|
||||
static HTAB *timezone_cache = NULL;
|
||||
|
||||
static bool
|
||||
init_timezone_hashtable(void)
|
||||
{
|
||||
@ -1013,14 +1014,18 @@ pg_tzset(const char *name)
|
||||
HASH_FIND,
|
||||
NULL);
|
||||
if (tzp)
|
||||
{
|
||||
/* Timezone found in cache, nothing more to do */
|
||||
return tzp;
|
||||
}
|
||||
|
||||
if (tzload(name, &tz.state) != 0)
|
||||
{
|
||||
if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0)
|
||||
{
|
||||
/* Unknown timezone. Fail our call instead of loading GMT! */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(tz.TZname, name);
|
||||
@ -1031,9 +1036,6 @@ pg_tzset(const char *name)
|
||||
HASH_ENTER,
|
||||
NULL);
|
||||
|
||||
if (!tzp)
|
||||
return NULL;
|
||||
|
||||
strcpy(tzp->TZname, tz.TZname);
|
||||
memcpy(&tzp->state, &tz.state, sizeof(tz.state));
|
||||
|
||||
|
Reference in New Issue
Block a user