Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f99e931

Browse files
committed
Properly clean PGresult
1 parent 55e8608 commit f99e931

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/backup.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -928,10 +928,13 @@ check_system_identifiers(void)
928928
"SELECT system_identifier FROM pg_control_system()",
929929
0, NULL);
930930
val = PQgetvalue(res, 0, 0);
931-
PQclear(res);
932931

933932
if (!parse_uint64(val, &system_id_conn))
933+
{
934+
PQclear(res);
934935
elog(ERROR, "%s is not system_identifier", val);
936+
}
937+
PQclear(res);
935938

936939
if (system_id_conn != system_identifier)
937940
elog(ERROR, "Backup data directory was initialized for system id %ld, but connected instance system id is %ld",
@@ -1204,10 +1207,11 @@ pg_ptrack_clear(void)
12041207
static bool
12051208
pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
12061209
{
1207-
char *params[2];
1208-
PGresult *res_db;
1209-
PGresult *res;
1210-
char *result;
1210+
char *params[2];
1211+
char *dbname;
1212+
PGresult *res_db;
1213+
PGresult *res;
1214+
char *result;
12111215

12121216
params[0] = palloc(64);
12131217
params[1] = palloc(64);
@@ -1223,15 +1227,15 @@ pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
12231227
if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1)
12241228
return false;
12251229

1226-
dbname = pstrdup(PQgetvalue(res_db, 0, 0));
1227-
PQclear(res_db);
1230+
dbname = PQgetvalue(res_db, 0, 0);
12281231

12291232
/* Always backup all files from template0 database */
12301233
if (strcmp(dbname, "template0") == 0)
12311234
{
1232-
pfree(dbname);
1235+
PQclear(res_db);
12331236
return true;
12341237
}
1238+
PQclear(res_db);
12351239

12361240
sprintf(params[0], "%i", dbOid);
12371241
sprintf(params[1], "%i", tblspcOid);
@@ -1262,16 +1266,17 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
12621266
PGconn *tmp_conn;
12631267
PGresult *res_db,
12641268
*res;
1265-
char *dbname;
12661269
char *params[2];
12671270
char *result;
12681271

12691272
params[0] = palloc(64);
12701273
params[1] = palloc(64);
12711274

1272-
/* regular file (not in directory 'global') */
1275+
/* regular file (not in directory 'global') */
12731276
if (db_oid != 0)
12741277
{
1278+
char *dbname;
1279+
12751280
sprintf(params[0], "%i", db_oid);
12761281
res_db = pgut_execute(backup_conn,
12771282
"SELECT datname FROM pg_database WHERE oid=$1",
@@ -1283,12 +1288,11 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
12831288
if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1)
12841289
return NULL;
12851290

1286-
dbname = pstrdup(PQgetvalue(res_db, 0, 0));
1287-
PQclear(res_db);
1291+
dbname = PQgetvalue(res_db, 0, 0);
12881292

12891293
if (strcmp(dbname, "template0") == 0)
12901294
{
1291-
pfree(dbname);
1295+
PQclear(res_db);
12921296
return NULL;
12931297
}
12941298

@@ -1300,10 +1304,9 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
13001304

13011305
if (PQnfields(res) != 1)
13021306
elog(ERROR, "cannot get ptrack file from database \"%s\" by tablespace oid %u and relation oid %u",
1303-
dbname, tablespace_oid, rel_filenode);
1304-
pfree(dbname);
1307+
dbname, tablespace_oid, rel_filenode);
1308+
PQclear(res_db);
13051309
pgut_disconnect(tmp_conn);
1306-
13071310
}
13081311
/* file in directory 'global' */
13091312
else
@@ -1795,17 +1798,19 @@ checkpoint_timeout(void)
17951798

17961799
res = pgut_execute(backup_conn, "show checkpoint_timeout", 0, NULL);
17971800
val = PQgetvalue(res, 0, 0);
1798-
PQclear(res);
17991801

18001802
if (!parse_int(val, &val_int, OPTION_UNIT_S, &hintmsg))
18011803
{
1804+
PQclear(res);
18021805
if (hintmsg)
18031806
elog(ERROR, "Invalid value of checkout_timeout %s: %s", val,
18041807
hintmsg);
18051808
else
18061809
elog(ERROR, "Invalid value of checkout_timeout %s", val);
18071810
}
18081811

1812+
PQclear(res);
1813+
18091814
return val_int;
18101815
}
18111816

0 commit comments

Comments
 (0)