Prevent coredump in current_schemas() if someone has just deleted a

schema that was in our search path.
This commit is contained in:
Tom Lane 2003-04-27 23:22:13 +00:00
parent 4089d25175
commit 1045655a25
1 changed files with 10 additions and 6 deletions

View File

@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.43 2003/03/10 22:28:18 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.44 2003/04/27 23:22:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -246,6 +246,8 @@ current_schema(PG_FUNCTION_ARGS)
if (search_path == NIL) if (search_path == NIL)
PG_RETURN_NULL(); PG_RETURN_NULL();
nspname = get_namespace_name(lfirsto(search_path)); nspname = get_namespace_name(lfirsto(search_path));
if (!nspname)
PG_RETURN_NULL(); /* recently-deleted namespace? */
PG_RETURN_DATUM(DirectFunctionCall1(namein, CStringGetDatum(nspname))); PG_RETURN_DATUM(DirectFunctionCall1(namein, CStringGetDatum(nspname)));
} }
@ -253,25 +255,27 @@ Datum
current_schemas(PG_FUNCTION_ARGS) current_schemas(PG_FUNCTION_ARGS)
{ {
List *search_path = fetch_search_path(PG_GETARG_BOOL(0)); List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
int nnames = length(search_path);
Datum *names; Datum *names;
int i; int i;
ArrayType *array; ArrayType *array;
/* +1 here is just to avoid palloc(0) error */ /* +1 here is just to avoid palloc(0) error */
names = (Datum *) palloc((nnames + 1) * sizeof(Datum)); names = (Datum *) palloc((length(search_path) + 1) * sizeof(Datum));
i = 0; i = 0;
while (search_path) while (search_path)
{ {
char *nspname; char *nspname;
nspname = get_namespace_name(lfirsto(search_path)); nspname = get_namespace_name(lfirsto(search_path));
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname)); if (nspname) /* watch out for deleted namespace */
i++; {
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
i++;
}
search_path = lnext(search_path); search_path = lnext(search_path);
} }
array = construct_array(names, nnames, array = construct_array(names, i,
NAMEOID, NAMEOID,
NAMEDATALEN, /* sizeof(Name) */ NAMEDATALEN, /* sizeof(Name) */
false, /* Name is not by-val */ false, /* Name is not by-val */