diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-06-16 21:50:56 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-07-03 11:47:15 +0200 |
commit | 02c408e21a6e78ff246ea7a1beb4669634fa9c4c (patch) | |
tree | 7e4cf03f3de7e32af266b739e12c6600d871ed45 /src/bin/psql/command.c | |
parent | 098c703d308fa88dc9e3f9f623ca023ce4717794 (diff) | |
download | postgresql-02c408e21a6e78ff246ea7a1beb4669634fa9c4c.tar.gz postgresql-02c408e21a6e78ff246ea7a1beb4669634fa9c4c.zip |
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/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 66 |
1 files changed, 22 insertions, 44 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 653943b87a6..f3c5196c901 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -595,8 +595,7 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd) success = false; } - if (opt) - free(opt); + free(opt); } else ignore_slash_options(scan_state); @@ -769,8 +768,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) break; } - if (pattern2) - free(pattern2); + free(pattern2); } break; case 'a': @@ -881,8 +879,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) OT_NORMAL, NULL, true); success = listDbRoleSettings(pattern, pattern2); - if (pattern2) - free(pattern2); + free(pattern2); } else status = PSQL_CMD_UNKNOWN; @@ -963,8 +960,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) status = PSQL_CMD_UNKNOWN; } - if (pattern) - free(pattern); + free(pattern); } else ignore_slash_options(scan_state); @@ -1092,10 +1088,8 @@ exec_command_edit(PsqlScanState scan_state, bool active_branch, else status = PSQL_CMD_ERROR; } - if (fname) - free(fname); - if (ln) - free(ln); + free(fname); + free(ln); } } else @@ -1204,8 +1198,7 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, status = PSQL_CMD_NEWEDIT; } - if (obj_desc) - free(obj_desc); + free(obj_desc); } else ignore_slash_whole_line(scan_state); @@ -1920,8 +1913,7 @@ exec_command_list(PsqlScanState scan_state, bool active_branch, const char *cmd) success = listAllDbs(pattern, show_verbose); - if (pattern) - free(pattern); + free(pattern); } else ignore_slash_options(scan_state); @@ -2136,10 +2128,8 @@ exec_command_password(PsqlScanState scan_state, bool active_branch) } free(user); - if (pw1) - free(pw1); - if (pw2) - free(pw2); + free(pw1); + free(pw2); termPQExpBuffer(&buf); } else @@ -2214,10 +2204,8 @@ exec_command_prompt(PsqlScanState scan_state, bool active_branch, (result && !SetVariable(pset.vars, opt, result))) success = false; - if (result) - free(result); - if (prompt_text) - free(prompt_text); + free(result); + free(prompt_text); free(opt); } } @@ -2522,8 +2510,7 @@ exec_command_sf_sv(PsqlScanState scan_state, bool active_branch, ClosePager(output); } - if (obj_desc) - free(obj_desc); + free(obj_desc); destroyPQExpBuffer(buf); } else @@ -2802,8 +2789,7 @@ exec_command_z(PsqlScanState scan_state, bool active_branch) OT_NORMAL, NULL, true); success = permissionsList(pattern); - if (pattern) - free(pattern); + free(pattern); } else ignore_slash_options(scan_state); @@ -2853,8 +2839,7 @@ exec_command_slash_command_help(PsqlScanState scan_state, bool active_branch) else slashUsage(pset.popt.topt.pager); - if (opt0) - free(opt0); + free(opt0); } else ignore_slash_options(scan_state); @@ -2994,8 +2979,7 @@ ignore_slash_filepipe(PsqlScanState scan_state) char *arg = psql_scan_slash_option(scan_state, OT_FILEPIPE, NULL, false); - if (arg) - free(arg); + free(arg); } /* @@ -3011,8 +2995,7 @@ ignore_slash_whole_line(PsqlScanState scan_state) char *arg = psql_scan_slash_option(scan_state, OT_WHOLE_LINE, NULL, false); - if (arg) - free(arg); + free(arg); } /* @@ -4779,16 +4762,11 @@ restorePsetInfo(printQueryOpt *popt, printQueryOpt *save) /* Free all the old data we're about to overwrite the pointers to. */ /* topt.line_style points to const data that need not be duplicated */ - if (popt->topt.fieldSep.separator) - free(popt->topt.fieldSep.separator); - if (popt->topt.recordSep.separator) - free(popt->topt.recordSep.separator); - if (popt->topt.tableAttr) - free(popt->topt.tableAttr); - if (popt->nullPrint) - free(popt->nullPrint); - if (popt->title) - free(popt->title); + free(popt->topt.fieldSep.separator); + free(popt->topt.recordSep.separator); + free(popt->topt.tableAttr); + free(popt->nullPrint); + free(popt->title); /* * footers and translate_columns are never set in psql's print settings, |