mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
Changed pg_version() prototype in order to remove the small memory leak
This commit is contained in:
@@ -64,10 +64,9 @@ is_standby(PGconn *conn)
|
|||||||
* if 8 or inferior returns an empty string
|
* if 8 or inferior returns an empty string
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
pg_version(PGconn *conn)
|
pg_version(PGconn *conn, char* major_version)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char *major_version;
|
|
||||||
|
|
||||||
int major_version1;
|
int major_version1;
|
||||||
char *major_version2;
|
char *major_version2;
|
||||||
@@ -85,12 +84,10 @@ pg_version(PGconn *conn)
|
|||||||
major_version2 = PQgetvalue(res, 0, 1);
|
major_version2 = PQgetvalue(res, 0, 1);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/* FIX: this is never deallocated */
|
|
||||||
major_version = malloc(10);
|
|
||||||
if (major_version1 >= 9)
|
if (major_version1 >= 9)
|
||||||
{
|
{
|
||||||
/* form a major version string */
|
/* 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
|
else
|
||||||
strcpy(major_version, "");
|
strcpy(major_version, "");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error);
|
PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error);
|
||||||
bool is_standby(PGconn *conn);
|
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);
|
bool guc_setted(PGconn *conn, const char *parameter, const char *op, const char *value);
|
||||||
const char *get_cluster_size(PGconn *conn);
|
const char *get_cluster_size(PGconn *conn);
|
||||||
PGconn * getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id);
|
PGconn * getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id);
|
||||||
|
|||||||
28
repmgr.c
28
repmgr.c
@@ -287,7 +287,7 @@ do_master_register(void)
|
|||||||
char conninfo[MAXLEN];
|
char conninfo[MAXLEN];
|
||||||
|
|
||||||
bool schema_exists = false;
|
bool schema_exists = false;
|
||||||
const char *master_version = NULL;
|
char master_version[MAXVERSIONSTR];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the configuration file: repmgr.conf
|
* Read the configuration file: repmgr.conf
|
||||||
@@ -303,7 +303,7 @@ do_master_register(void)
|
|||||||
conn = establishDBConnection(conninfo, true);
|
conn = establishDBConnection(conninfo, true);
|
||||||
|
|
||||||
/* master should be v9 or better */
|
/* master should be v9 or better */
|
||||||
master_version = pg_version(conn);
|
pg_version(conn, master_version);
|
||||||
if (strcmp(master_version, "") == 0)
|
if (strcmp(master_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -464,8 +464,8 @@ do_standby_register(void)
|
|||||||
int myLocalId = -1;
|
int myLocalId = -1;
|
||||||
char conninfo[MAXLEN];
|
char conninfo[MAXLEN];
|
||||||
|
|
||||||
const char *master_version = NULL;
|
char master_version[MAXVERSIONSTR];
|
||||||
const char *standby_version = NULL;
|
char standby_version[MAXVERSIONSTR];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the configuration file: repmgr.conf
|
* Read the configuration file: repmgr.conf
|
||||||
@@ -481,7 +481,7 @@ do_standby_register(void)
|
|||||||
conn = establishDBConnection(conninfo, true);
|
conn = establishDBConnection(conninfo, true);
|
||||||
|
|
||||||
/* should be v9 or better */
|
/* should be v9 or better */
|
||||||
standby_version = pg_version(conn);
|
pg_version(conn, standby_version);
|
||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -523,7 +523,7 @@ do_standby_register(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* master should be v9 or better */
|
/* master should be v9 or better */
|
||||||
master_version = pg_version(master_conn);
|
pg_version(master_conn, master_version);
|
||||||
if (strcmp(master_version, "") == 0)
|
if (strcmp(master_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -600,7 +600,7 @@ do_standby_clone(void)
|
|||||||
const char *first_wal_segment = NULL;
|
const char *first_wal_segment = NULL;
|
||||||
const char *last_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 hasn't been provided, initialize to current directory */
|
||||||
if (dest_dir == NULL)
|
if (dest_dir == NULL)
|
||||||
@@ -683,7 +683,7 @@ do_standby_clone(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* primary should be v9 or better */
|
/* primary should be v9 or better */
|
||||||
master_version = pg_version(conn);
|
pg_version(conn, master_version);
|
||||||
if (strcmp(master_version, "") == 0)
|
if (strcmp(master_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -968,7 +968,7 @@ do_standby_promote(void)
|
|||||||
char recovery_file_path[MAXLEN];
|
char recovery_file_path[MAXLEN];
|
||||||
char recovery_done_path[MAXLEN];
|
char recovery_done_path[MAXLEN];
|
||||||
|
|
||||||
const char *standby_version = NULL;
|
char standby_version[MAXVERSIONSTR];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the configuration file: repmgr.conf
|
* Read the configuration file: repmgr.conf
|
||||||
@@ -985,7 +985,7 @@ do_standby_promote(void)
|
|||||||
conn = establishDBConnection(conninfo, true);
|
conn = establishDBConnection(conninfo, true);
|
||||||
|
|
||||||
/* we need v9 or better */
|
/* we need v9 or better */
|
||||||
standby_version = pg_version(conn);
|
pg_version(conn, standby_version);
|
||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -1074,8 +1074,8 @@ do_standby_follow(void)
|
|||||||
int r;
|
int r;
|
||||||
char data_dir[MAXLEN];
|
char data_dir[MAXLEN];
|
||||||
|
|
||||||
const char *master_version = NULL;
|
char master_version[MAXVERSIONSTR];
|
||||||
const char *standby_version = NULL;
|
char standby_version[MAXVERSIONSTR];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the configuration file: repmgr.conf
|
* Read the configuration file: repmgr.conf
|
||||||
@@ -1099,7 +1099,7 @@ do_standby_follow(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* should be v9 or better */
|
/* should be v9 or better */
|
||||||
standby_version = pg_version(conn);
|
pg_version(conn, standby_version);
|
||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -1125,7 +1125,7 @@ do_standby_follow(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* should be v9 or better */
|
/* should be v9 or better */
|
||||||
master_version = pg_version(master_conn);
|
pg_version(master_conn, master_version);
|
||||||
if (strcmp(master_version, "") == 0)
|
if (strcmp(master_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
|
|||||||
1
repmgr.h
1
repmgr.h
@@ -20,5 +20,6 @@
|
|||||||
|
|
||||||
#define MAXLEN 80
|
#define MAXLEN 80
|
||||||
#define CONFIG_FILE "repmgr.conf"
|
#define CONFIG_FILE "repmgr.conf"
|
||||||
|
#define MAXVERSIONSTR 16
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ main(int argc, char **argv)
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
char conninfo[MAXLEN];
|
char conninfo[MAXLEN];
|
||||||
const char *standby_version = NULL;
|
char standby_version[MAXVERSIONSTR];
|
||||||
|
|
||||||
progname = get_progname(argv[0]);
|
progname = get_progname(argv[0]);
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ main(int argc, char **argv)
|
|||||||
myLocalConn = establishDBConnection(conninfo, true);
|
myLocalConn = establishDBConnection(conninfo, true);
|
||||||
|
|
||||||
/* should be v9 or better */
|
/* should be v9 or better */
|
||||||
standby_version = pg_version(myLocalConn);
|
pg_version(myLocalConn, standby_version);
|
||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
|
|||||||
Reference in New Issue
Block a user