Skip to content

Commit df3f152

Browse files
committed
Don't assume free(NULL) is OK. Yes, I know ANSI C says it is.
1 parent c74dc12 commit df3f152

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.69 2001/06/06 17:07:46 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.70 2001/06/13 19:52:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -36,7 +36,6 @@
3636
#ifdef CYR_RECODE
3737
unsigned char RecodeForwTable[128];
3838
unsigned char RecodeBackTable[128];
39-
4039
#endif
4140

4241
ProcessingMode Mode = InitProcessing;
@@ -82,7 +81,11 @@ IgnoreSystemIndexes(bool mode)
8281
void
8382
SetDatabasePath(const char *path)
8483
{
85-
free(DatabasePath);
84+
if (DatabasePath)
85+
{
86+
free(DatabasePath);
87+
DatabasePath = NULL;
88+
}
8689
/* use strdup since this is done before memory contexts are set up */
8790
if (path)
8891
{
@@ -94,7 +97,12 @@ SetDatabasePath(const char *path)
9497
void
9598
SetDatabaseName(const char *name)
9699
{
97-
free(DatabaseName);
100+
if (DatabaseName)
101+
{
102+
free(DatabaseName);
103+
DatabaseName = NULL;
104+
}
105+
/* use strdup since this is done before memory contexts are set up */
98106
if (name)
99107
{
100108
DatabaseName = strdup(name);
@@ -112,8 +120,6 @@ SetDataDir(const char *dir)
112120
char *new;
113121

114122
AssertArg(dir);
115-
if (DataDir)
116-
free(DataDir);
117123

118124
if (dir[0] != '/')
119125
{
@@ -155,6 +161,8 @@ SetDataDir(const char *dir)
155161
elog(FATAL, "out of memory");
156162
}
157163

164+
if (DataDir)
165+
free(DataDir);
158166
DataDir = new;
159167
}
160168

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy