Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

Commit

Permalink
fix some memory leak and fix testlogic for is_standby is_witness
Browse files Browse the repository at this point in the history
* is_standby() must be tested *after* is_witness else we think we are in a master
* remove SELECT * in favor of SELECT witness
  • Loading branch information
Cédric Villemain authored and Jaime Casanova committed Mar 9, 2011
1 parent cc5d06e commit c9299ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dbutils.c
Expand Up @@ -99,7 +99,7 @@ is_witness(PGconn *conn, char *cluster, int node_id)
bool result;
char sqlquery[MAXQUERY];

snprintf(sqlquery, MAXQUERY, "SELECT * from repmgr_%s.repl_nodes where id = %d",
snprintf(sqlquery, MAXQUERY, "SELECT witness from repmgr_%s.repl_nodes where id = %d",
cluster, node_id);
res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
Expand All @@ -110,7 +110,7 @@ is_witness(PGconn *conn, char *cluster, int node_id)
exit(1);
}

if (strcmp(PQgetvalue(res, 0, 3), "f") == 0)
if (strcmp(PQgetvalue(res, 0, 0), "f") == 0)
result = false;
else
result = true;
Expand Down
11 changes: 6 additions & 5 deletions repmgrd.c
Expand Up @@ -182,10 +182,10 @@ main(int argc, char **argv)
* Set my server mode, establish a connection to primary
* and start monitor
*/
if (is_standby(myLocalConn))
myLocalMode = STANDBY_MODE;
else if (is_witness(myLocalConn, myClusterName, myLocalId))
if (is_witness(myLocalConn, myClusterName, myLocalId))
myLocalMode = WITNESS_MODE;
else if (is_standby(myLocalConn))
myLocalMode = STANDBY_MODE;
else /* is the master */
myLocalMode = PRIMARY_MODE;

Expand Down Expand Up @@ -642,6 +642,7 @@ CheckPrimaryConnection(void)
PQclear(res);
return;
}
PQclear(res);
}


Expand Down Expand Up @@ -822,7 +823,7 @@ update_shared_memory(char *last_wal_standby_applied)
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
log_warning(_("Cannot update this standby's shared memory: %s", PQerrorMessage(myLocalConn)));
PQclear(res);
/* XXX is this enough reason to terminate this repmgrd? */
}
} // TODO memory leak here ?
PQclear(res);
}

0 comments on commit c9299ad

Please sign in to comment.