diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 0dda180..be288e3 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -2908,7 +2908,7 @@ keep_going: /* We will come back to here until there is } /* - * If a read-write connection is requisted check for same. + * If a read-write connection is requested check for same. */ if (conn->target_session_attrs != NULL && strcmp(conn->target_session_attrs, "read-write") == 0) @@ -2988,15 +2988,23 @@ keep_going: /* We will come back to here until there is /* No more addresses to try. So we fail. */ goto error_return; } + PQclear(res); - termPQExpBuffer(&savedMessage); + /* + * Call PQgetResult() again to consume NULL result. + * Anything else is an error and will be dealt with below. + */ + if ((res = PQgetResult(conn)) == NULL) + { + termPQExpBuffer(&savedMessage); - /* We can release the address lists now. */ - release_all_addrinfo(conn); + /* We can release the address lists now. */ + release_all_addrinfo(conn); - /* We are open for business! */ - conn->status = CONNECTION_OK; - return PGRES_POLLING_OK; + /* We are open for business! */ + conn->status = CONNECTION_OK; + return PGRES_POLLING_OK; + } } /*