1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-21 12:05:57 +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

@ -809,7 +809,6 @@ error:
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not write file \"%s\": %m", errmsg("could not write file \"%s\": %m",
PGSS_DUMP_FILE ".tmp"))); PGSS_DUMP_FILE ".tmp")));
if (qbuffer)
free(qbuffer); free(qbuffer);
if (file) if (file)
FreeFile(file); FreeFile(file);
@ -1657,7 +1656,6 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
pgss->extent != extent || pgss->extent != extent ||
pgss->gc_count != gc_count) pgss->gc_count != gc_count)
{ {
if (qbuffer)
free(qbuffer); free(qbuffer);
qbuffer = qtext_load_file(&qbuffer_size); qbuffer = qtext_load_file(&qbuffer_size);
} }
@ -1842,7 +1840,6 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
LWLockRelease(pgss->lock); LWLockRelease(pgss->lock);
if (qbuffer)
free(qbuffer); free(qbuffer);
} }
@ -2446,7 +2443,6 @@ gc_fail:
/* clean up resources */ /* clean up resources */
if (qfile) if (qfile)
FreeFile(qfile); FreeFile(qfile);
if (qbuffer)
free(qbuffer); free(qbuffer);
/* /*

View File

@ -292,7 +292,6 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
if (ptr && len <= 36) if (ptr && len <= 36)
strcpy(strbuf + (36 - len), ptr); strcpy(strbuf + (36 - len), ptr);
} }
if (str)
free(str); free(str);
} }
@ -366,7 +365,6 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
if (status == uuid_s_ok) if (status == uuid_s_ok)
strlcpy(strbuf, str, 37); strlcpy(strbuf, str, 37);
if (str)
free(str); free(str);
if (status != uuid_s_ok) if (status != uuid_s_ok)

View File

@ -288,7 +288,6 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV); SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
free(name); free(name);
if (value)
free(value); free(value);
break; break;
} }

View File

@ -2020,10 +2020,7 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
fail: fail:
/* free up whatever we allocated */ /* free up whatever we allocated */
for (i = 0; i < num_msg; i++) for (i = 0; i < num_msg; i++)
{
if (reply[i].resp != NULL)
free(reply[i].resp); free(reply[i].resp);
}
free(reply); free(reply);
return PAM_CONV_ERR; return PAM_CONV_ERR;

View File

@ -854,7 +854,6 @@ PostmasterMain(int argc, char *argv[])
SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV); SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
free(name); free(name);
if (value)
free(value); free(value);
break; break;
} }

View File

@ -930,9 +930,7 @@ pg_ctype_get_cache(pg_wc_probefunc probefunc, int cclasscode)
* Failure, clean up * Failure, clean up
*/ */
out_of_memory: out_of_memory:
if (pcc->cv.chrs)
free(pcc->cv.chrs); free(pcc->cv.chrs);
if (pcc->cv.ranges)
free(pcc->cv.ranges); free(pcc->cv.ranges);
free(pcc); free(pcc);

View File

@ -3896,7 +3896,6 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
} }
SetConfigOption(name, value, ctx, gucsource); SetConfigOption(name, value, ctx, gucsource);
free(name); free(name);
if (value)
free(value); free(value);
break; break;
} }

View File

@ -374,25 +374,15 @@ assign_locale_messages(const char *newval, void *extra)
static void static void
free_struct_lconv(struct lconv *s) free_struct_lconv(struct lconv *s)
{ {
if (s->decimal_point)
free(s->decimal_point); free(s->decimal_point);
if (s->thousands_sep)
free(s->thousands_sep); free(s->thousands_sep);
if (s->grouping)
free(s->grouping); free(s->grouping);
if (s->int_curr_symbol)
free(s->int_curr_symbol); free(s->int_curr_symbol);
if (s->currency_symbol)
free(s->currency_symbol); free(s->currency_symbol);
if (s->mon_decimal_point)
free(s->mon_decimal_point); free(s->mon_decimal_point);
if (s->mon_thousands_sep)
free(s->mon_thousands_sep); free(s->mon_thousands_sep);
if (s->mon_grouping)
free(s->mon_grouping); free(s->mon_grouping);
if (s->positive_sign)
free(s->positive_sign); free(s->positive_sign);
if (s->negative_sign)
free(s->negative_sign); free(s->negative_sign);
} }

View File

@ -1985,7 +1985,6 @@ set_syslog_parameters(const char *ident, int facility)
closelog(); closelog();
openlog_done = false; openlog_done = false;
} }
if (syslog_ident)
free(syslog_ident); free(syslog_ident);
syslog_ident = strdup(ident); syslog_ident = strdup(ident);
/* if the strdup fails, we will cope in write_syslog() */ /* if the strdup fails, we will cope in write_syslog() */

View File

@ -417,7 +417,6 @@ SetDataDir(const char *dir)
/* If presented path is relative, convert to absolute */ /* If presented path is relative, convert to absolute */
new = make_absolute_path(dir); new = make_absolute_path(dir);
if (DataDir)
free(DataDir); free(DataDir);
DataDir = new; DataDir = new;
} }

View File

@ -5483,7 +5483,6 @@ build_guc_variables(void)
for (i = 0; ConfigureNamesEnum[i].gen.name; i++) for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen; guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
if (guc_variables)
free(guc_variables); free(guc_variables);
guc_variables = guc_vars; guc_variables = guc_vars;
num_guc_variables = num_vars; num_guc_variables = num_vars;
@ -6880,7 +6879,6 @@ ReportGUCOption(struct config_generic *record)
* set last_reported to NULL and thereby possibly make a duplicate * set last_reported to NULL and thereby possibly make a duplicate
* report later. * report later.
*/ */
if (record->last_reported)
free(record->last_reported); free(record->last_reported);
record->last_reported = strdup(val); record->last_reported = strdup(val);
} }
@ -8356,7 +8354,6 @@ set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
return; return;
sourcefile = guc_strdup(elevel, sourcefile); sourcefile = guc_strdup(elevel, sourcefile);
if (record->sourcefile)
free(record->sourcefile); free(record->sourcefile);
record->sourcefile = sourcefile; record->sourcefile = sourcefile;
record->sourceline = sourceline; record->sourceline = sourceline;
@ -8877,7 +8874,6 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
if (record->vartype == PGC_STRING && newval.stringval != NULL) if (record->vartype == PGC_STRING && newval.stringval != NULL)
free(newval.stringval); free(newval.stringval);
if (newextra)
free(newextra); free(newextra);
/* /*
@ -11225,11 +11221,8 @@ RestoreGUCState(void *gucstate)
* pointers. * pointers.
*/ */
Assert(gconf->stack == NULL); Assert(gconf->stack == NULL);
if (gconf->extra)
free(gconf->extra); free(gconf->extra);
if (gconf->last_reported) /* probably can't happen */
free(gconf->last_reported); free(gconf->last_reported);
if (gconf->sourcefile)
free(gconf->sourcefile); free(gconf->sourcefile);
switch (gconf->vartype) switch (gconf->vartype)
{ {
@ -11261,7 +11254,6 @@ RestoreGUCState(void *gucstate)
{ {
struct config_string *conf = (struct config_string *) gconf; struct config_string *conf = (struct config_string *) gconf;
if (*conf->variable)
free(*conf->variable); free(*conf->variable);
if (conf->reset_val && conf->reset_val != *conf->variable) if (conf->reset_val && conf->reset_val != *conf->variable)
free(conf->reset_val); free(conf->reset_val);

View File

@ -775,7 +775,6 @@ progress_update_filename(const char *filename)
/* We needn't maintain this variable if not doing verbose reports. */ /* We needn't maintain this variable if not doing verbose reports. */
if (showprogress && verbose) if (showprogress && verbose)
{ {
if (progress_filename)
free(progress_filename); free(progress_filename);
if (filename) if (filename)
progress_filename = pg_strdup(filename); progress_filename = pg_strdup(filename);

View File

@ -154,7 +154,6 @@ GetConnection(void)
/* Get a new password if appropriate */ /* Get a new password if appropriate */
if (need_password) if (need_password)
{ {
if (password)
free(password); free(password);
password = simple_prompt("Password: ", false); password = simple_prompt("Password: ", false);
need_password = false; need_password = false;

View File

@ -98,7 +98,6 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
/* Parse the acls array */ /* Parse the acls array */
if (!parsePGArray(acls, &aclitems, &naclitems)) if (!parsePGArray(acls, &aclitems, &naclitems))
{ {
if (aclitems)
free(aclitems); free(aclitems);
return false; return false;
} }
@ -106,9 +105,7 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
/* Parse the baseacls too */ /* Parse the baseacls too */
if (!parsePGArray(baseacls, &baseitems, &nbaseitems)) if (!parsePGArray(baseacls, &baseitems, &nbaseitems))
{ {
if (aclitems)
free(aclitems); free(aclitems);
if (baseitems)
free(baseitems); free(baseitems);
return false; return false;
} }
@ -298,13 +295,9 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
destroyPQExpBuffer(firstsql); destroyPQExpBuffer(firstsql);
destroyPQExpBuffer(secondsql); destroyPQExpBuffer(secondsql);
if (aclitems)
free(aclitems); free(aclitems);
if (baseitems)
free(baseitems); free(baseitems);
if (grantitems)
free(grantitems); free(grantitems);
if (revokeitems)
free(revokeitems); free(revokeitems);
return ok; return ok;

View File

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

View File

@ -632,7 +632,6 @@ _skipData(ArchiveHandle *AH)
{ {
if (blkLen > buflen) if (blkLen > buflen)
{ {
if (buf)
free(buf); free(buf);
buf = (char *) pg_malloc(blkLen); buf = (char *) pg_malloc(blkLen);
buflen = blkLen; buflen = blkLen;
@ -649,7 +648,6 @@ _skipData(ArchiveHandle *AH)
blkLen = ReadInt(AH); blkLen = ReadInt(AH);
} }
if (buf)
free(buf); free(buf);
} }

View File

@ -204,7 +204,6 @@ ConnectDatabase(Archive *AHX,
*/ */
if (PQconnectionUsedPassword(AH->connection)) if (PQconnectionUsedPassword(AH->connection))
{ {
if (AH->savedPassword)
free(AH->savedPassword); free(AH->savedPassword);
AH->savedPassword = pg_strdup(PQpass(AH->connection)); AH->savedPassword = pg_strdup(PQpass(AH->connection));
} }

View File

@ -412,7 +412,6 @@ tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
* handle, and we don't use temp files. * handle, and we don't use temp files.
*/ */
if (th->targetFile)
free(th->targetFile); free(th->targetFile);
th->nFH = NULL; th->nFH = NULL;

View File

@ -3339,7 +3339,6 @@ dumpSearchPath(Archive *AH)
/* Also save it in AH->searchpath, in case we're doing plain text dump */ /* Also save it in AH->searchpath, in case we're doing plain text dump */
AH->searchpath = pg_strdup(qry->data); AH->searchpath = pg_strdup(qry->data);
if (schemanames)
free(schemanames); free(schemanames);
PQclear(res); PQclear(res);
destroyPQExpBuffer(qry); destroyPQExpBuffer(qry);
@ -4614,7 +4613,6 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
subinfo->dobj.catId, 0, subinfo->dobj.dumpId); subinfo->dobj.catId, 0, subinfo->dobj.dumpId);
destroyPQExpBuffer(publications); destroyPQExpBuffer(publications);
if (pubnames)
free(pubnames); free(pubnames);
destroyPQExpBuffer(delq); destroyPQExpBuffer(delq);
@ -11908,11 +11906,9 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
destroyPQExpBuffer(delqry); destroyPQExpBuffer(delqry);
destroyPQExpBuffer(asPart); destroyPQExpBuffer(asPart);
free(funcsig); free(funcsig);
if (funcfullsig)
free(funcfullsig); free(funcfullsig);
free(funcsig_tag); free(funcsig_tag);
free(qual_funcsig); free(qual_funcsig);
if (configitems)
free(configitems); free(configitems);
} }
@ -13658,7 +13654,6 @@ dumpAgg(Archive *fout, const AggInfo *agginfo)
agginfo->aggfn.rolname, &agginfo->aggfn.dacl); agginfo->aggfn.rolname, &agginfo->aggfn.dacl);
free(aggsig); free(aggsig);
if (aggfullsig)
free(aggfullsig); free(aggfullsig);
free(aggsig_tag); free(aggsig_tag);
@ -15713,11 +15708,8 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
tbinfo->attfdwoptions[j]); tbinfo->attfdwoptions[j]);
} /* end loop over columns */ } /* end loop over columns */
if (partkeydef)
free(partkeydef); free(partkeydef);
if (ftoptions)
free(ftoptions); free(ftoptions);
if (srvname)
free(srvname); free(srvname);
} }
@ -16105,9 +16097,7 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
.createStmt = q->data, .createStmt = q->data,
.dropStmt = delq->data)); .dropStmt = delq->data));
if (indstatcolsarray)
free(indstatcolsarray); free(indstatcolsarray);
if (indstatvalsarray)
free(indstatvalsarray); free(indstatvalsarray);
} }

View File

@ -1500,9 +1500,7 @@ connectDatabase(const char *dbname, const char *connection_string,
char *err_msg = NULL; char *err_msg = NULL;
int i = 0; int i = 0;
if (keywords)
free(keywords); free(keywords);
if (values)
free(values); free(values);
if (conn_opts) if (conn_opts)
PQconninfoFree(conn_opts); PQconninfoFree(conn_opts);

View File

@ -1852,7 +1852,6 @@ putVariable(Variables *variables, const char *context, char *name,
/* dup then free, in case value is pointing at this variable */ /* dup then free, in case value is pointing at this variable */
val = pg_strdup(value); val = pg_strdup(value);
if (var->svalue)
free(var->svalue); free(var->svalue);
var->svalue = val; var->svalue = val;
var->value.type = PGBT_NO_VALUE; var->value.type = PGBT_NO_VALUE;
@ -1872,7 +1871,6 @@ putVariableValue(Variables *variables, const char *context, char *name,
if (!var) if (!var)
return false; return false;
if (var->svalue)
free(var->svalue); free(var->svalue);
var->svalue = NULL; var->svalue = NULL;
var->value = *value; var->value = *value;

View File

@ -595,7 +595,6 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
success = false; success = false;
} }
if (opt)
free(opt); free(opt);
} }
else else
@ -769,7 +768,6 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
break; break;
} }
if (pattern2)
free(pattern2); free(pattern2);
} }
break; break;
@ -881,7 +879,6 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
OT_NORMAL, NULL, true); OT_NORMAL, NULL, true);
success = listDbRoleSettings(pattern, pattern2); success = listDbRoleSettings(pattern, pattern2);
if (pattern2)
free(pattern2); free(pattern2);
} }
else else
@ -963,7 +960,6 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
status = PSQL_CMD_UNKNOWN; status = PSQL_CMD_UNKNOWN;
} }
if (pattern)
free(pattern); free(pattern);
} }
else else
@ -1092,9 +1088,7 @@ exec_command_edit(PsqlScanState scan_state, bool active_branch,
else else
status = PSQL_CMD_ERROR; status = PSQL_CMD_ERROR;
} }
if (fname)
free(fname); free(fname);
if (ln)
free(ln); free(ln);
} }
} }
@ -1204,7 +1198,6 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch,
status = PSQL_CMD_NEWEDIT; status = PSQL_CMD_NEWEDIT;
} }
if (obj_desc)
free(obj_desc); free(obj_desc);
} }
else else
@ -1920,7 +1913,6 @@ exec_command_list(PsqlScanState scan_state, bool active_branch, const char *cmd)
success = listAllDbs(pattern, show_verbose); success = listAllDbs(pattern, show_verbose);
if (pattern)
free(pattern); free(pattern);
} }
else else
@ -2136,9 +2128,7 @@ exec_command_password(PsqlScanState scan_state, bool active_branch)
} }
free(user); free(user);
if (pw1)
free(pw1); free(pw1);
if (pw2)
free(pw2); free(pw2);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
} }
@ -2214,9 +2204,7 @@ exec_command_prompt(PsqlScanState scan_state, bool active_branch,
(result && !SetVariable(pset.vars, opt, result))) (result && !SetVariable(pset.vars, opt, result)))
success = false; success = false;
if (result)
free(result); free(result);
if (prompt_text)
free(prompt_text); free(prompt_text);
free(opt); free(opt);
} }
@ -2522,7 +2510,6 @@ exec_command_sf_sv(PsqlScanState scan_state, bool active_branch,
ClosePager(output); ClosePager(output);
} }
if (obj_desc)
free(obj_desc); free(obj_desc);
destroyPQExpBuffer(buf); destroyPQExpBuffer(buf);
} }
@ -2802,7 +2789,6 @@ exec_command_z(PsqlScanState scan_state, bool active_branch)
OT_NORMAL, NULL, true); OT_NORMAL, NULL, true);
success = permissionsList(pattern); success = permissionsList(pattern);
if (pattern)
free(pattern); free(pattern);
} }
else else
@ -2853,7 +2839,6 @@ exec_command_slash_command_help(PsqlScanState scan_state, bool active_branch)
else else
slashUsage(pset.popt.topt.pager); slashUsage(pset.popt.topt.pager);
if (opt0)
free(opt0); free(opt0);
} }
else else
@ -2994,7 +2979,6 @@ ignore_slash_filepipe(PsqlScanState scan_state)
char *arg = psql_scan_slash_option(scan_state, char *arg = psql_scan_slash_option(scan_state,
OT_FILEPIPE, NULL, false); OT_FILEPIPE, NULL, false);
if (arg)
free(arg); free(arg);
} }
@ -3011,7 +2995,6 @@ ignore_slash_whole_line(PsqlScanState scan_state)
char *arg = psql_scan_slash_option(scan_state, char *arg = psql_scan_slash_option(scan_state,
OT_WHOLE_LINE, NULL, false); OT_WHOLE_LINE, NULL, false);
if (arg)
free(arg); free(arg);
} }
@ -4779,15 +4762,10 @@ restorePsetInfo(printQueryOpt *popt, printQueryOpt *save)
/* Free all the old data we're about to overwrite the pointers to. */ /* 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 */ /* topt.line_style points to const data that need not be duplicated */
if (popt->topt.fieldSep.separator)
free(popt->topt.fieldSep.separator); free(popt->topt.fieldSep.separator);
if (popt->topt.recordSep.separator)
free(popt->topt.recordSep.separator); free(popt->topt.recordSep.separator);
if (popt->topt.tableAttr)
free(popt->topt.tableAttr); free(popt->topt.tableAttr);
if (popt->nullPrint)
free(popt->nullPrint); free(popt->nullPrint);
if (popt->title)
free(popt->title); free(popt->title);
/* /*

View File

@ -389,7 +389,6 @@ do_copy(const char *args)
pg_log_error("%s: %s", options->file, pg_log_error("%s: %s", options->file,
reason ? reason : ""); reason ? reason : "");
if (reason)
free(reason); free(reason);
} }
success = false; success = false;

View File

@ -1786,7 +1786,6 @@ describeOneTableDetails(const char *schemaname,
printQuery(res, &myopt, pset.queryFout, false, pset.logfile); printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
if (footers[0])
free(footers[0]); free(footers[0]);
retval = true; retval = true;
@ -3491,7 +3490,6 @@ error_return:
termPQExpBuffer(&title); termPQExpBuffer(&title);
termPQExpBuffer(&tmpbuf); termPQExpBuffer(&tmpbuf);
if (view_def)
free(view_def); free(view_def);
if (res) if (res)

View File

@ -158,7 +158,6 @@ pg_send_history(PQExpBuffer history_buf)
else else
{ {
/* Save each previous line for ignoredups processing */ /* Save each previous line for ignoredups processing */
if (prev_hist)
free(prev_hist); free(prev_hist);
prev_hist = pg_strdup(s); prev_hist = pg_strdup(s);
/* And send it to readline */ /* And send it to readline */

View File

@ -4754,10 +4754,8 @@ psql_completion(const char *text, int start, int end)
free(previous_words); free(previous_words);
free(words_buffer); free(words_buffer);
free(text_copy); free(text_copy);
if (completion_ref_object)
free(completion_ref_object); free(completion_ref_object);
completion_ref_object = NULL; completion_ref_object = NULL;
if (completion_ref_schema)
free(completion_ref_schema); free(completion_ref_schema);
completion_ref_schema = NULL; completion_ref_schema = NULL;
@ -5160,11 +5158,8 @@ _complete_from_query(const char *simple_query,
/* Clean up */ /* Clean up */
termPQExpBuffer(&query_buffer); termPQExpBuffer(&query_buffer);
free(e_object_like); free(e_object_like);
if (e_schemaname)
free(e_schemaname); free(e_schemaname);
if (e_ref_object)
free(e_ref_object); free(e_ref_object);
if (e_ref_schema)
free(e_ref_schema); free(e_ref_schema);
} }

View File

@ -104,7 +104,6 @@ pg_strdup(const char *in)
void void
pg_free(void *ptr) pg_free(void *ptr)
{ {
if (ptr != NULL)
free(ptr); free(ptr);
} }

View File

@ -99,7 +99,6 @@ connectDatabase(const ConnParams *cparams, const char *progname,
cparams->prompt_password != TRI_NO) cparams->prompt_password != TRI_NO)
{ {
PQfinish(conn); PQfinish(conn);
if (password)
free(password); free(password);
password = simple_prompt("Password: ", false); password = simple_prompt("Password: ", false);
new_pass = true; new_pass = true;

View File

@ -810,7 +810,6 @@ appendReloptionsArray(PQExpBuffer buffer, const char *reloptions,
if (!parsePGArray(reloptions, &options, &noptions)) if (!parsePGArray(reloptions, &options, &noptions))
{ {
if (options)
free(options); free(options);
return false; return false;
} }
@ -854,7 +853,6 @@ appendReloptionsArray(PQExpBuffer buffer, const char *reloptions,
appendStringLiteral(buffer, value, encoding, std_strings); appendStringLiteral(buffer, value, encoding, std_strings);
} }
if (options)
free(options); free(options);
return true; return true;

View File

@ -16,11 +16,7 @@
#define init_var(v) memset(v,0,sizeof(numeric)) #define init_var(v) memset(v,0,sizeof(numeric))
#define digitbuf_alloc(size) ((NumericDigit *) pgtypes_alloc(size)) #define digitbuf_alloc(size) ((NumericDigit *) pgtypes_alloc(size))
#define digitbuf_free(buf) \ #define digitbuf_free(buf) free(buf)
do { \
if ((buf) != NULL) \
free(buf); \
} while (0)
/* ---------- /* ----------

View File

@ -113,7 +113,6 @@ drop_descriptor(char *name, char *connection)
&& strcmp(connection, i->connection) == 0)) && strcmp(connection, i->connection) == 0))
{ {
*lastptr = i->next; *lastptr = i->next;
if (i->connection)
free(i->connection); free(i->connection);
free(i->name); free(i->name);
free(i); free(i);

View File

@ -174,29 +174,20 @@ scram_free(void *opaq)
{ {
fe_scram_state *state = (fe_scram_state *) opaq; fe_scram_state *state = (fe_scram_state *) opaq;
if (state->password)
free(state->password); free(state->password);
if (state->sasl_mechanism)
free(state->sasl_mechanism); free(state->sasl_mechanism);
/* client messages */ /* client messages */
if (state->client_nonce)
free(state->client_nonce); free(state->client_nonce);
if (state->client_first_message_bare)
free(state->client_first_message_bare); free(state->client_first_message_bare);
if (state->client_final_message_without_proof)
free(state->client_final_message_without_proof); free(state->client_final_message_without_proof);
/* first message from server */ /* first message from server */
if (state->server_first_message)
free(state->server_first_message); free(state->server_first_message);
if (state->salt)
free(state->salt); free(state->salt);
if (state->nonce)
free(state->nonce); free(state->nonce);
/* final message from server */ /* final message from server */
if (state->server_final_message)
free(state->server_final_message); free(state->server_final_message);
free(state); free(state);
@ -941,7 +932,6 @@ pg_fe_scram_build_secret(const char *password, const char **errstr)
if (!pg_strong_random(saltbuf, SCRAM_DEFAULT_SALT_LEN)) if (!pg_strong_random(saltbuf, SCRAM_DEFAULT_SALT_LEN))
{ {
*errstr = _("failed to generate random salt"); *errstr = _("failed to generate random salt");
if (prep_password)
free(prep_password); free(prep_password);
return NULL; return NULL;
} }
@ -950,7 +940,6 @@ pg_fe_scram_build_secret(const char *password, const char **errstr)
SCRAM_DEFAULT_ITERATIONS, password, SCRAM_DEFAULT_ITERATIONS, password,
errstr); errstr);
if (prep_password)
free(prep_password); free(prep_password);
return result; return result;

View File

@ -107,7 +107,6 @@ pg_GSS_continue(PGconn *conn, int payloadlen)
NULL, NULL,
NULL); NULL);
if (ginbuf.value)
free(ginbuf.value); free(ginbuf.value);
if (goutbuf.length != 0) if (goutbuf.length != 0)
@ -270,7 +269,6 @@ pg_SSPI_continue(PGconn *conn, int payloadlen)
NULL); NULL);
/* we don't need the input anymore */ /* we don't need the input anymore */
if (inputbuf)
free(inputbuf); free(inputbuf);
if (r != SEC_E_OK && r != SEC_I_CONTINUE_NEEDED) if (r != SEC_E_OK && r != SEC_I_CONTINUE_NEEDED)
@ -604,20 +602,17 @@ pg_SASL_init(PGconn *conn, int payloadlen)
goto error; goto error;
termPQExpBuffer(&mechanism_buf); termPQExpBuffer(&mechanism_buf);
if (initialresponse)
free(initialresponse); free(initialresponse);
return STATUS_OK; return STATUS_OK;
error: error:
termPQExpBuffer(&mechanism_buf); termPQExpBuffer(&mechanism_buf);
if (initialresponse)
free(initialresponse); free(initialresponse);
return STATUS_ERROR; return STATUS_ERROR;
oom_error: oom_error:
termPQExpBuffer(&mechanism_buf); termPQExpBuffer(&mechanism_buf);
if (initialresponse)
free(initialresponse); free(initialresponse);
appendPQExpBufferStr(&conn->errorMessage, appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n")); libpq_gettext("out of memory\n"));
@ -831,7 +826,6 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
return STATUS_ERROR; return STATUS_ERROR;
} }
ret = pqPacketSend(conn, 'p', pwd_to_send, strlen(pwd_to_send) + 1); ret = pqPacketSend(conn, 'p', pwd_to_send, strlen(pwd_to_send) + 1);
if (crypt_pwd)
free(crypt_pwd); free(crypt_pwd);
return ret; return ret;
} }

View File

@ -540,7 +540,6 @@ pqFreeCommandQueue(PGcmdQueueEntry *queue)
PGcmdQueueEntry *cur = queue; PGcmdQueueEntry *cur = queue;
queue = cur->next; queue = cur->next;
if (cur->query)
free(cur->query); free(cur->query);
free(cur); free(cur);
} }
@ -593,7 +592,6 @@ pqDropServerData(PGconn *conn)
conn->sversion = 0; conn->sversion = 0;
/* Drop large-object lookup data */ /* Drop large-object lookup data */
if (conn->lobjfuncs)
free(conn->lobjfuncs); free(conn->lobjfuncs);
conn->lobjfuncs = NULL; conn->lobjfuncs = NULL;
@ -602,7 +600,6 @@ pqDropServerData(PGconn *conn)
conn->auth_req_received = false; conn->auth_req_received = false;
conn->password_needed = false; conn->password_needed = false;
conn->write_failed = false; conn->write_failed = false;
if (conn->write_err_msg)
free(conn->write_err_msg); free(conn->write_err_msg);
conn->write_err_msg = NULL; conn->write_err_msg = NULL;
conn->be_pid = 0; conn->be_pid = 0;
@ -898,7 +895,6 @@ fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
{ {
char **connmember = (char **) ((char *) conn + option->connofs); char **connmember = (char **) ((char *) conn + option->connofs);
if (*connmember)
free(*connmember); free(*connmember);
*connmember = strdup(tmp); *connmember = strdup(tmp);
if (*connmember == NULL) if (*connmember == NULL)
@ -1113,7 +1109,6 @@ connectOptions2(PGconn *conn)
} }
else else
{ {
if (ch->host)
free(ch->host); free(ch->host);
/* /*
@ -1186,7 +1181,6 @@ connectOptions2(PGconn *conn)
*/ */
if (conn->pguser == NULL || conn->pguser[0] == '\0') if (conn->pguser == NULL || conn->pguser[0] == '\0')
{ {
if (conn->pguser)
free(conn->pguser); free(conn->pguser);
conn->pguser = pg_fe_getauthname(&conn->errorMessage); conn->pguser = pg_fe_getauthname(&conn->errorMessage);
if (!conn->pguser) if (!conn->pguser)
@ -1201,7 +1195,6 @@ connectOptions2(PGconn *conn)
*/ */
if (conn->dbName == NULL || conn->dbName[0] == '\0') if (conn->dbName == NULL || conn->dbName[0] == '\0')
{ {
if (conn->dbName)
free(conn->dbName); free(conn->dbName);
conn->dbName = strdup(conn->pguser); conn->dbName = strdup(conn->pguser);
if (!conn->dbName) if (!conn->dbName)
@ -1221,7 +1214,6 @@ connectOptions2(PGconn *conn)
if (pqGetHomeDirectory(homedir, sizeof(homedir))) if (pqGetHomeDirectory(homedir, sizeof(homedir)))
{ {
if (conn->pgpassfile)
free(conn->pgpassfile); free(conn->pgpassfile);
conn->pgpassfile = malloc(MAXPGPATH); conn->pgpassfile = malloc(MAXPGPATH);
if (!conn->pgpassfile) if (!conn->pgpassfile)
@ -1548,7 +1540,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
/* Insert dbName parameter value into struct */ /* Insert dbName parameter value into struct */
if (dbName && dbName[0] != '\0') if (dbName && dbName[0] != '\0')
{ {
if (conn->dbName)
free(conn->dbName); free(conn->dbName);
conn->dbName = strdup(dbName); conn->dbName = strdup(dbName);
if (!conn->dbName) if (!conn->dbName)
@ -1562,7 +1553,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
*/ */
if (pghost && pghost[0] != '\0') if (pghost && pghost[0] != '\0')
{ {
if (conn->pghost)
free(conn->pghost); free(conn->pghost);
conn->pghost = strdup(pghost); conn->pghost = strdup(pghost);
if (!conn->pghost) if (!conn->pghost)
@ -1571,7 +1561,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
if (pgport && pgport[0] != '\0') if (pgport && pgport[0] != '\0')
{ {
if (conn->pgport)
free(conn->pgport); free(conn->pgport);
conn->pgport = strdup(pgport); conn->pgport = strdup(pgport);
if (!conn->pgport) if (!conn->pgport)
@ -1580,7 +1569,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
if (pgoptions && pgoptions[0] != '\0') if (pgoptions && pgoptions[0] != '\0')
{ {
if (conn->pgoptions)
free(conn->pgoptions); free(conn->pgoptions);
conn->pgoptions = strdup(pgoptions); conn->pgoptions = strdup(pgoptions);
if (!conn->pgoptions) if (!conn->pgoptions)
@ -1589,7 +1577,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
if (login && login[0] != '\0') if (login && login[0] != '\0')
{ {
if (conn->pguser)
free(conn->pguser); free(conn->pguser);
conn->pguser = strdup(login); conn->pguser = strdup(login);
if (!conn->pguser) if (!conn->pguser)
@ -1598,7 +1585,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
if (pwd && pwd[0] != '\0') if (pwd && pwd[0] != '\0')
{ {
if (conn->pgpass)
free(conn->pgpass); free(conn->pgpass);
conn->pgpass = strdup(pwd); conn->pgpass = strdup(pwd);
if (!conn->pgpass) if (!conn->pgpass)
@ -4044,10 +4030,8 @@ makeEmptyPGconn(void)
static void static void
freePGconn(PGconn *conn) freePGconn(PGconn *conn)
{ {
int i;
/* let any event procs clean up their state data */ /* let any event procs clean up their state data */
for (i = 0; i < conn->nEvents; i++) for (int i = 0; i < conn->nEvents; i++)
{ {
PGEventConnDestroy evt; PGEventConnDestroy evt;
@ -4058,15 +4042,10 @@ freePGconn(PGconn *conn)
} }
/* clean up pg_conn_host structures */ /* clean up pg_conn_host structures */
if (conn->connhost != NULL) for (int i = 0; i < conn->nconnhost; ++i)
{ {
for (i = 0; i < conn->nconnhost; ++i)
{
if (conn->connhost[i].host != NULL)
free(conn->connhost[i].host); free(conn->connhost[i].host);
if (conn->connhost[i].hostaddr != NULL)
free(conn->connhost[i].hostaddr); free(conn->connhost[i].hostaddr);
if (conn->connhost[i].port != NULL)
free(conn->connhost[i].port); free(conn->connhost[i].port);
if (conn->connhost[i].password != NULL) if (conn->connhost[i].password != NULL)
{ {
@ -4075,96 +4054,56 @@ freePGconn(PGconn *conn)
} }
} }
free(conn->connhost); free(conn->connhost);
}
if (conn->client_encoding_initial)
free(conn->client_encoding_initial); free(conn->client_encoding_initial);
if (conn->events)
free(conn->events); free(conn->events);
if (conn->pghost)
free(conn->pghost); free(conn->pghost);
if (conn->pghostaddr)
free(conn->pghostaddr); free(conn->pghostaddr);
if (conn->pgport)
free(conn->pgport); free(conn->pgport);
if (conn->connect_timeout)
free(conn->connect_timeout); free(conn->connect_timeout);
if (conn->pgtcp_user_timeout)
free(conn->pgtcp_user_timeout); free(conn->pgtcp_user_timeout);
if (conn->pgoptions)
free(conn->pgoptions); free(conn->pgoptions);
if (conn->appname)
free(conn->appname); free(conn->appname);
if (conn->fbappname)
free(conn->fbappname); free(conn->fbappname);
if (conn->dbName)
free(conn->dbName); free(conn->dbName);
if (conn->replication)
free(conn->replication); free(conn->replication);
if (conn->pguser)
free(conn->pguser); free(conn->pguser);
if (conn->pgpass) if (conn->pgpass)
{ {
explicit_bzero(conn->pgpass, strlen(conn->pgpass)); explicit_bzero(conn->pgpass, strlen(conn->pgpass));
free(conn->pgpass); free(conn->pgpass);
} }
if (conn->pgpassfile)
free(conn->pgpassfile); free(conn->pgpassfile);
if (conn->channel_binding)
free(conn->channel_binding); free(conn->channel_binding);
if (conn->keepalives)
free(conn->keepalives); free(conn->keepalives);
if (conn->keepalives_idle)
free(conn->keepalives_idle); free(conn->keepalives_idle);
if (conn->keepalives_interval)
free(conn->keepalives_interval); free(conn->keepalives_interval);
if (conn->keepalives_count)
free(conn->keepalives_count); free(conn->keepalives_count);
if (conn->sslmode)
free(conn->sslmode); free(conn->sslmode);
if (conn->sslcert)
free(conn->sslcert); free(conn->sslcert);
if (conn->sslkey)
free(conn->sslkey); free(conn->sslkey);
if (conn->sslpassword) if (conn->sslpassword)
{ {
explicit_bzero(conn->sslpassword, strlen(conn->sslpassword)); explicit_bzero(conn->sslpassword, strlen(conn->sslpassword));
free(conn->sslpassword); free(conn->sslpassword);
} }
if (conn->sslrootcert)
free(conn->sslrootcert); free(conn->sslrootcert);
if (conn->sslcrl)
free(conn->sslcrl); free(conn->sslcrl);
if (conn->sslcrldir)
free(conn->sslcrldir); free(conn->sslcrldir);
if (conn->sslcompression)
free(conn->sslcompression); free(conn->sslcompression);
if (conn->sslsni)
free(conn->sslsni); free(conn->sslsni);
if (conn->requirepeer)
free(conn->requirepeer); free(conn->requirepeer);
if (conn->ssl_min_protocol_version)
free(conn->ssl_min_protocol_version); free(conn->ssl_min_protocol_version);
if (conn->ssl_max_protocol_version)
free(conn->ssl_max_protocol_version); free(conn->ssl_max_protocol_version);
if (conn->gssencmode)
free(conn->gssencmode); free(conn->gssencmode);
if (conn->krbsrvname)
free(conn->krbsrvname); free(conn->krbsrvname);
if (conn->gsslib)
free(conn->gsslib); free(conn->gsslib);
if (conn->connip)
free(conn->connip); free(conn->connip);
/* Note that conn->Pfdebug is not ours to close or free */ /* Note that conn->Pfdebug is not ours to close or free */
if (conn->write_err_msg)
free(conn->write_err_msg); free(conn->write_err_msg);
if (conn->inBuffer)
free(conn->inBuffer); free(conn->inBuffer);
if (conn->outBuffer)
free(conn->outBuffer); free(conn->outBuffer);
if (conn->rowBuf)
free(conn->rowBuf); free(conn->rowBuf);
if (conn->target_session_attrs)
free(conn->target_session_attrs); free(conn->target_session_attrs);
termPQExpBuffer(&conn->errorMessage); termPQExpBuffer(&conn->errorMessage);
termPQExpBuffer(&conn->workBuffer); termPQExpBuffer(&conn->workBuffer);
@ -4433,7 +4372,6 @@ fail:
void void
PQfreeCancel(PGcancel *cancel) PQfreeCancel(PGcancel *cancel)
{ {
if (cancel)
free(cancel); free(cancel);
} }
@ -5883,7 +5821,6 @@ conninfo_array_parse(const char *const *keywords, const char *const *values,
{ {
if (strcmp(options[k].keyword, str_option->keyword) == 0) if (strcmp(options[k].keyword, str_option->keyword) == 0)
{ {
if (options[k].val)
free(options[k].val); free(options[k].val);
options[k].val = strdup(str_option->val); options[k].val = strdup(str_option->val);
if (!options[k].val) if (!options[k].val)
@ -5912,7 +5849,6 @@ conninfo_array_parse(const char *const *keywords, const char *const *values,
/* /*
* Store the value, overriding previous settings * Store the value, overriding previous settings
*/ */
if (option->val)
free(option->val); free(option->val);
option->val = strdup(pvalue); option->val = strdup(pvalue);
if (!option->val) if (!option->val)
@ -6344,7 +6280,6 @@ conninfo_uri_parse_options(PQconninfoOption *options, const char *uri,
cleanup: cleanup:
termPQExpBuffer(&hostbuf); termPQExpBuffer(&hostbuf);
termPQExpBuffer(&portbuf); termPQExpBuffer(&portbuf);
if (buf)
free(buf); free(buf);
return retval; return retval;
} }
@ -6655,7 +6590,6 @@ conninfo_storeval(PQconninfoOption *connOptions,
} }
} }
if (option->val)
free(option->val); free(option->val);
option->val = value_copy; option->val = value_copy;
@ -6735,16 +6669,11 @@ PQconninfo(PGconn *conn)
void void
PQconninfoFree(PQconninfoOption *connOptions) PQconninfoFree(PQconninfoOption *connOptions)
{ {
PQconninfoOption *option;
if (connOptions == NULL) if (connOptions == NULL)
return; return;
for (option = connOptions; option->keyword != NULL; option++) for (PQconninfoOption *option = connOptions; option->keyword != NULL; option++)
{
if (option->val != NULL)
free(option->val); free(option->val);
}
free(connOptions); free(connOptions);
} }

View File

@ -742,7 +742,6 @@ PQclear(PGresult *res)
free(res->events[i].name); free(res->events[i].name);
} }
if (res->events)
free(res->events); free(res->events);
/* Free all the subsidiary blocks */ /* Free all the subsidiary blocks */
@ -753,7 +752,6 @@ PQclear(PGresult *res)
} }
/* Free the top-level tuple pointer array */ /* Free the top-level tuple pointer array */
if (res->tuples)
free(res->tuples); free(res->tuples);
/* zero out the pointer fields to catch programming errors */ /* zero out the pointer fields to catch programming errors */

View File

@ -303,11 +303,8 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
fputs("</table>\n", fout); fputs("</table>\n", fout);
exit: exit:
if (fieldMax)
free(fieldMax); free(fieldMax);
if (fieldNotNum)
free(fieldNotNum); free(fieldNotNum);
if (border)
free(border); free(border);
if (fields) if (fields)
{ {
@ -315,14 +312,10 @@ exit:
size_t numfields = ((size_t) nTups + 1) * (size_t) nFields; size_t numfields = ((size_t) nTups + 1) * (size_t) nFields;
while (numfields-- > 0) while (numfields-- > 0)
{
if (fields[numfields])
free(fields[numfields]); free(fields[numfields]);
}
free(fields); free(fields);
} }
if (fieldNames) free(fieldNames);
free((void *) fieldNames);
if (usePipe) if (usePipe)
{ {
#ifdef WIN32 #ifdef WIN32
@ -679,7 +672,6 @@ PQdisplayTuples(const PGresult *res,
fflush(fp); fflush(fp);
if (fLength)
free(fLength); free(fLength);
} }
@ -763,7 +755,6 @@ PQprintTuples(const PGresult *res,
} }
} }
if (tborder)
free(tborder); free(tborder);
} }

View File

@ -309,7 +309,6 @@ pq_verify_peer_name_matches_certificate(PGconn *conn)
} }
/* clean up */ /* clean up */
if (first_name)
free(first_name); free(first_name);
return (rc == 1); return (rc == 1);

View File

@ -270,7 +270,6 @@ freeaddrinfo(struct addrinfo *res)
} }
#endif #endif
if (res->ai_addr)
free(res->ai_addr); free(res->ai_addr);
free(res); free(res);
} }