1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

Remove redundant null pointer checks before free()

Per applicable standards, free() with a null pointer is a no-op.
Systems that don't observe that are ancient and no longer relevant.
Some PostgreSQL code already required this behavior, so this change
does not introduce any new requirements, just makes the code more
consistent.

Discussion: https://www.postgresql.org/message-id/flat/dac5d2d0-98f5-94d9-8e69-46da2413593d%40enterprisedb.com
This commit is contained in:
Peter Eisentraut
2022-06-16 21:50:56 +02:00
parent 098c703d30
commit 02c408e21a
38 changed files with 213 additions and 435 deletions

View File

@@ -640,8 +640,7 @@ RestoreArchive(Archive *AHX)
* If we treated users as pg_dump'able objects then we'd need to reset
* currUser here too.
*/
if (AH->currSchema)
free(AH->currSchema);
free(AH->currSchema);
AH->currSchema = NULL;
}
@@ -2067,8 +2066,7 @@ _discoverArchiveFormat(ArchiveHandle *AH)
pg_log_debug("attempting to ascertain archive format");
if (AH->lookahead)
free(AH->lookahead);
free(AH->lookahead);
AH->readHeader = 0;
AH->lookaheadSize = 512;
@@ -3178,21 +3176,17 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname)
* NOTE: currUser keeps track of what the imaginary session user in our
* script is. It's now effectively reset to the original userID.
*/
if (AH->currUser)
free(AH->currUser);
free(AH->currUser);
AH->currUser = NULL;
/* don't assume we still know the output schema, tablespace, etc either */
if (AH->currSchema)
free(AH->currSchema);
free(AH->currSchema);
AH->currSchema = NULL;
if (AH->currTableAm)
free(AH->currTableAm);
free(AH->currTableAm);
AH->currTableAm = NULL;
if (AH->currTablespace)
free(AH->currTablespace);
free(AH->currTablespace);
AH->currTablespace = NULL;
/* re-establish fixed state */
@@ -3219,8 +3213,7 @@ _becomeUser(ArchiveHandle *AH, const char *user)
* NOTE: currUser keeps track of what the imaginary session user in our
* script is
*/
if (AH->currUser)
free(AH->currUser);
free(AH->currUser);
AH->currUser = pg_strdup(user);
}
@@ -3285,8 +3278,7 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
else
ahprintf(AH, "%s;\n\n", qry->data);
if (AH->currSchema)
free(AH->currSchema);
free(AH->currSchema);
AH->currSchema = pg_strdup(schemaName);
destroyPQExpBuffer(qry);
@@ -3347,8 +3339,7 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
else
ahprintf(AH, "%s;\n\n", qry->data);
if (AH->currTablespace)
free(AH->currTablespace);
free(AH->currTablespace);
AH->currTablespace = pg_strdup(want);
destroyPQExpBuffer(qry);
@@ -3399,8 +3390,7 @@ _selectTableAccessMethod(ArchiveHandle *AH, const char *tableam)
destroyPQExpBuffer(cmd);
if (AH->currTableAm)
free(AH->currTableAm);
free(AH->currTableAm);
AH->currTableAm = pg_strdup(want);
}
@@ -3659,8 +3649,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
*/
if (_tocEntryIsACL(te))
{
if (AH->currUser)
free(AH->currUser);
free(AH->currUser);
AH->currUser = NULL;
}
}
@@ -3991,17 +3980,13 @@ restore_toc_entries_prefork(ArchiveHandle *AH, TocEntry *pending_list)
DisconnectDatabase(&AH->public);
/* blow away any transient state from the old connection */
if (AH->currUser)
free(AH->currUser);
free(AH->currUser);
AH->currUser = NULL;
if (AH->currSchema)
free(AH->currSchema);
free(AH->currSchema);
AH->currSchema = NULL;
if (AH->currTablespace)
free(AH->currTablespace);
free(AH->currTablespace);
AH->currTablespace = NULL;
if (AH->currTableAm)
free(AH->currTableAm);
free(AH->currTableAm);
AH->currTableAm = NULL;
}
@@ -4842,16 +4827,11 @@ DeCloneArchive(ArchiveHandle *AH)
destroyPQExpBuffer(AH->sqlparse.curCmd);
/* Clear any connection-local state */
if (AH->currUser)
free(AH->currUser);
if (AH->currSchema)
free(AH->currSchema);
if (AH->currTablespace)
free(AH->currTablespace);
if (AH->currTableAm)
free(AH->currTableAm);
if (AH->savedPassword)
free(AH->savedPassword);
free(AH->currUser);
free(AH->currSchema);
free(AH->currTablespace);
free(AH->currTableAm);
free(AH->savedPassword);
free(AH);
}