Don't assume free(NULL) is OK. Yes, I know ANSI C says it is.

This commit is contained in:
Tom Lane 2001-06-13 19:52:33 +00:00
parent c74dc1281f
commit df3f152ed7

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.69 2001/06/06 17:07:46 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.70 2001/06/13 19:52:33 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -36,7 +36,6 @@
#ifdef CYR_RECODE #ifdef CYR_RECODE
unsigned char RecodeForwTable[128]; unsigned char RecodeForwTable[128];
unsigned char RecodeBackTable[128]; unsigned char RecodeBackTable[128];
#endif #endif
ProcessingMode Mode = InitProcessing; ProcessingMode Mode = InitProcessing;
@ -82,7 +81,11 @@ IgnoreSystemIndexes(bool mode)
void void
SetDatabasePath(const char *path) SetDatabasePath(const char *path)
{ {
if (DatabasePath)
{
free(DatabasePath); free(DatabasePath);
DatabasePath = NULL;
}
/* use strdup since this is done before memory contexts are set up */ /* use strdup since this is done before memory contexts are set up */
if (path) if (path)
{ {
@ -94,7 +97,12 @@ SetDatabasePath(const char *path)
void void
SetDatabaseName(const char *name) SetDatabaseName(const char *name)
{ {
if (DatabaseName)
{
free(DatabaseName); free(DatabaseName);
DatabaseName = NULL;
}
/* use strdup since this is done before memory contexts are set up */
if (name) if (name)
{ {
DatabaseName = strdup(name); DatabaseName = strdup(name);
@ -112,8 +120,6 @@ SetDataDir(const char *dir)
char *new; char *new;
AssertArg(dir); AssertArg(dir);
if (DataDir)
free(DataDir);
if (dir[0] != '/') if (dir[0] != '/')
{ {
@ -155,6 +161,8 @@ SetDataDir(const char *dir)
elog(FATAL, "out of memory"); elog(FATAL, "out of memory");
} }
if (DataDir)
free(DataDir);
DataDir = new; DataDir = new;
} }