summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_archiver.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-06-16 21:50:56 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-07-03 11:47:15 +0200
commit02c408e21a6e78ff246ea7a1beb4669634fa9c4c (patch)
tree7e4cf03f3de7e32af266b739e12c6600d871ed45 /src/bin/pg_dump/pg_backup_archiver.c
parent098c703d308fa88dc9e3f9f623ca023ce4717794 (diff)
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
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c60
1 files changed, 20 insertions, 40 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 77fe51a3a53..233198afc0c 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -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);
}