Fix get_cluster_size()

Was returning a pointer to a cleared PQresult
This commit is contained in:
Ian Barwick
2015-01-06 10:30:33 +09:00
parent 718024454e
commit 3033f2dfaf
3 changed files with 14 additions and 12 deletions

View File

@@ -266,11 +266,10 @@ guc_set_typed(PGconn *conn, const char *parameter, const char *op,
}
const char *
get_cluster_size(PGconn *conn)
bool
get_cluster_size(PGconn *conn, char *size)
{
PGresult *res;
const char *size = NULL;
char sqlquery[QUERY_STR_LEN];
sqlquery_snprintf(
@@ -283,14 +282,15 @@ get_cluster_size(PGconn *conn)
{
log_err(_("Get cluster size PQexec failed: %s"),
PQerrorMessage(conn));
}
else
{
size = PQgetvalue(res, 0, 0);
PQclear(res);
return false;
}
strncpy(size, PQgetvalue(res, 0, 0), MAXLEN);
PQclear(res);
return size;
return true;
}
@@ -307,10 +307,12 @@ get_data_directory(PGconn *conn, char *data_directory)
log_debug(_("get_data_directory(): %s\n"), sqlquery);
res = PQexec(conn, sqlquery);
if (res == NULL || PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1)
{
log_err(_("get_data_directory() - PQexec failed: %s"),
PQerrorMessage(conn));
PQclear(res);
return false;
}

View File

@@ -31,7 +31,7 @@ int is_standby(PGconn *conn);
int is_witness(PGconn *conn, char *schema, char *cluster, int node_id);
bool is_pgup(PGconn *conn, int timeout);
int get_server_version(PGconn *conn, char *server_version);
const char *get_cluster_size(PGconn *conn);
bool get_cluster_size(PGconn *conn, char *size);
bool get_data_directory(PGconn *conn, char *data_directory);
int guc_set(PGconn *conn, const char *parameter, const char *op,

View File

@@ -832,7 +832,7 @@ do_standby_clone(void)
PGresult *res;
char sqlquery[QUERY_STR_LEN];
const char *cluster_size;
char cluster_size[MAXLEN];
int r = 0,
retval = SUCCESS;
@@ -941,9 +941,9 @@ do_standby_clone(void)
PQclear(res);
cluster_size = get_cluster_size(conn);
if (cluster_size == NULL)
if(get_cluster_size(conn, cluster_size) == false)
exit(ERR_DB_QUERY);
log_info(_("Successfully connected to master. Current installation size is %s\n"),
cluster_size);