Changed pg_version() prototype in order to remove the small memory leak

This commit is contained in:
Gabriele Bartolini
2010-12-16 22:48:19 +01:00
parent f2bec9a08f
commit d88783a4d9
5 changed files with 20 additions and 22 deletions

View File

@@ -64,10 +64,9 @@ is_standby(PGconn *conn)
* if 8 or inferior returns an empty string
*/
char *
pg_version(PGconn *conn)
pg_version(PGconn *conn, char* major_version)
{
PGresult *res;
char *major_version;
int major_version1;
char *major_version2;
@@ -85,12 +84,10 @@ pg_version(PGconn *conn)
major_version2 = PQgetvalue(res, 0, 1);
PQclear(res);
/* FIX: this is never deallocated */
major_version = malloc(10);
if (major_version1 >= 9)
{
/* form a major version string */
sprintf(major_version, "%d.%s", major_version1, major_version2);
snprintf(major_version, MAXVERSIONSTR, "%d.%s", major_version1, major_version2);
}
else
strcpy(major_version, "");

View File

@@ -6,7 +6,7 @@
PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error);
bool is_standby(PGconn *conn);
char *pg_version(PGconn *conn);
char *pg_version(PGconn *conn, char* major_version);
bool guc_setted(PGconn *conn, const char *parameter, const char *op, const char *value);
const char *get_cluster_size(PGconn *conn);
PGconn * getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id);

View File

@@ -287,7 +287,7 @@ do_master_register(void)
char conninfo[MAXLEN];
bool schema_exists = false;
const char *master_version = NULL;
char master_version[MAXVERSIONSTR];
/*
* Read the configuration file: repmgr.conf
@@ -303,7 +303,7 @@ do_master_register(void)
conn = establishDBConnection(conninfo, true);
/* master should be v9 or better */
master_version = pg_version(conn);
pg_version(conn, master_version);
if (strcmp(master_version, "") == 0)
{
PQfinish(conn);
@@ -464,8 +464,8 @@ do_standby_register(void)
int myLocalId = -1;
char conninfo[MAXLEN];
const char *master_version = NULL;
const char *standby_version = NULL;
char master_version[MAXVERSIONSTR];
char standby_version[MAXVERSIONSTR];
/*
* Read the configuration file: repmgr.conf
@@ -481,7 +481,7 @@ do_standby_register(void)
conn = establishDBConnection(conninfo, true);
/* should be v9 or better */
standby_version = pg_version(conn);
pg_version(conn, standby_version);
if (strcmp(standby_version, "") == 0)
{
PQfinish(conn);
@@ -523,7 +523,7 @@ do_standby_register(void)
return;
/* master should be v9 or better */
master_version = pg_version(master_conn);
pg_version(master_conn, master_version);
if (strcmp(master_version, "") == 0)
{
PQfinish(conn);
@@ -600,7 +600,7 @@ do_standby_clone(void)
const char *first_wal_segment = NULL;
const char *last_wal_segment = NULL;
const char *master_version = NULL;
char master_version[MAXVERSIONSTR];
/* if dest_dir hasn't been provided, initialize to current directory */
if (dest_dir == NULL)
@@ -683,7 +683,7 @@ do_standby_clone(void)
}
/* primary should be v9 or better */
master_version = pg_version(conn);
pg_version(conn, master_version);
if (strcmp(master_version, "") == 0)
{
PQfinish(conn);
@@ -968,7 +968,7 @@ do_standby_promote(void)
char recovery_file_path[MAXLEN];
char recovery_done_path[MAXLEN];
const char *standby_version = NULL;
char standby_version[MAXVERSIONSTR];
/*
* Read the configuration file: repmgr.conf
@@ -985,7 +985,7 @@ do_standby_promote(void)
conn = establishDBConnection(conninfo, true);
/* we need v9 or better */
standby_version = pg_version(conn);
pg_version(conn, standby_version);
if (strcmp(standby_version, "") == 0)
{
PQfinish(conn);
@@ -1074,8 +1074,8 @@ do_standby_follow(void)
int r;
char data_dir[MAXLEN];
const char *master_version = NULL;
const char *standby_version = NULL;
char master_version[MAXVERSIONSTR];
char standby_version[MAXVERSIONSTR];
/*
* Read the configuration file: repmgr.conf
@@ -1099,7 +1099,7 @@ do_standby_follow(void)
}
/* should be v9 or better */
standby_version = pg_version(conn);
pg_version(conn, standby_version);
if (strcmp(standby_version, "") == 0)
{
PQfinish(conn);
@@ -1125,7 +1125,7 @@ do_standby_follow(void)
}
/* should be v9 or better */
master_version = pg_version(master_conn);
pg_version(master_conn, master_version);
if (strcmp(master_version, "") == 0)
{
PQfinish(conn);

View File

@@ -20,5 +20,6 @@
#define MAXLEN 80
#define CONFIG_FILE "repmgr.conf"
#define MAXVERSIONSTR 16
#endif

View File

@@ -81,7 +81,7 @@ main(int argc, char **argv)
int c;
char conninfo[MAXLEN];
const char *standby_version = NULL;
char standby_version[MAXVERSIONSTR];
progname = get_progname(argv[0]);
@@ -138,7 +138,7 @@ main(int argc, char **argv)
myLocalConn = establishDBConnection(conninfo, true);
/* should be v9 or better */
standby_version = pg_version(myLocalConn);
pg_version(myLocalConn, standby_version);
if (strcmp(standby_version, "") == 0)
{
PQfinish(myLocalConn);