These functions already had the free()-like behavior of handling null
pointers as a no-op. But it wasn't documented, so add it explicitly
to the documentation, too.
Discussion: https://www.postgresql.org/message-id/flat/
dac5d2d0-98f5-94d9-8e69-
46da2413593d%40enterprisedb.com
{
char *msg = pchomp(PQerrorMessage(conn));
- if (res)
- PQclear(res);
+ PQclear(res);
elog(ERROR, "%s: %s", p2, msg);
}
* leaking all the strings too, but those are in palloc'd memory that will
* get cleaned up eventually.
*/
- if (res)
- PQclear(res);
+ PQclear(res);
/*
* Format the basic errcontext string. Below, we'll add on something
return;
/* Release PGresult */
- if (dmstate->result)
- PQclear(dmstate->result);
+ PQclear(dmstate->result);
/* Release remote connection */
ReleaseConnection(dmstate->conn);
}
PG_FINALLY();
{
- if (res)
- PQclear(res);
+ PQclear(res);
}
PG_END_TRY();
}
}
PG_FINALLY();
{
- if (res)
- PQclear(res);
+ PQclear(res);
}
PG_END_TRY();
}
PG_CATCH();
{
- if (res)
- PQclear(res);
+ PQclear(res);
PG_RE_THROW();
}
PG_END_TRY();
}
PG_CATCH();
{
- if (dmstate->result)
- PQclear(dmstate->result);
+ PQclear(dmstate->result);
PG_RE_THROW();
}
PG_END_TRY();
}
PG_FINALLY();
{
- if (res)
- PQclear(res);
+ PQclear(res);
}
PG_END_TRY();
}
PG_CATCH();
{
- if (res)
- PQclear(res);
+ PQclear(res);
PG_RE_THROW();
}
PG_END_TRY();
}
PG_FINALLY();
{
- if (res)
- PQclear(res);
+ PQclear(res);
}
PG_END_TRY();
<synopsis>
void PQclear(PGresult *res);
</synopsis>
+
+ If the argument is a <symbol>NULL</symbol> pointer, no operation is
+ performed.
</para>
<para>
<synopsis>
void PQconninfoFree(PQconninfoOption *connOptions);
</synopsis>
+ If the argument is a <symbol>NULL</symbol> pointer, no operation is
+ performed.
</para>
<para>
PQfinish(tmpconn);
free(values);
free(keywords);
- if (conn_opts)
- PQconninfoFree(conn_opts);
+ PQconninfoFree(conn_opts);
return NULL;
}
/* Connection ok! */
free(values);
free(keywords);
- if (conn_opts)
- PQconninfoFree(conn_opts);
+ PQconninfoFree(conn_opts);
/*
* Set always-secure search path, so malicious users can't get control.
free(keywords);
free(values);
- if (conn_opts)
- PQconninfoFree(conn_opts);
+ PQconninfoFree(conn_opts);
/*
* Merge the connection info inputs given in form of connection string
/* Release locally allocated data, whether we succeeded or not */
pg_free(password);
- if (cinfo)
- PQconninfoFree(cinfo);
+ PQconninfoFree(cinfo);
if (!success)
{
{
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
- if (pset.last_error_result)
- PQclear(pset.last_error_result);
+ PQclear(pset.last_error_result);
pset.last_error_result = result;
break;
free(view_def);
- if (res)
- PQclear(res);
+ PQclear(res);
return retval;
}
r = (res && PQresultStatus(res) == PGRES_COMMAND_OK);
- if (res)
- PQclear(res);
+ PQclear(res);
return r;
}
if (!ecpg_check_PQresult(res, line, con->connection, compat))
break;
- if (desc->result != NULL)
- PQclear(desc->result);
+ PQclear(desc->result);
desc->result = res;
ret = true;
status = false;
else
{
- if (desc->result)
- PQclear(desc->result);
+ PQclear(desc->result);
desc->result = stmt->results;
clear_result = false;
ecpg_log("ecpg_process_output on line %d: putting result (%d tuples) into descriptor %s\n",
}
/* Something went wrong with "SHOW transaction_read_only". */
- if (res)
- PQclear(res);
+ PQclear(res);
/* Append error report to conn->errorMessage. */
appendPQExpBuffer(&conn->errorMessage,
}
/* Something went wrong with "SELECT pg_is_in_recovery()". */
- if (res)
- PQclear(res);
+ PQclear(res);
/* Append error report to conn->errorMessage. */
appendPQExpBuffer(&conn->errorMessage,
void
pqClearAsyncResult(PGconn *conn)
{
- if (conn->result)
- PQclear(conn->result);
+ PQclear(conn->result);
conn->result = NULL;
conn->error_result = false;
- if (conn->next_result)
- PQclear(conn->next_result);
+ PQclear(conn->next_result);
conn->next_result = NULL;
}
lastResult = NULL;
while ((result = PQgetResult(conn)) != NULL)
{
- if (lastResult)
- PQclear(lastResult);
+ PQclear(lastResult);
lastResult = result;
if (result->resultStatus == PGRES_COPY_IN ||
result->resultStatus == PGRES_COPY_OUT ||