Skip to content

Commit 57f620d

Browse files
committed
Copy dtmhost string on call to TuneToDtm.
1 parent da45ca5 commit 57f620d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

contrib/pg_dtm/libdtm.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,15 @@ static bool dtm_query(DTMConn dtm, char cmd, int argc, ...)
231231
return true;
232232
}
233233

234-
static char *dtmhost = "127.0.0.1";
235-
static int dtmport = 5431;
234+
static char *dtmhost = NULL;
235+
static int dtmport = 0;
236236

237237
void TuneToDtm(char *host, int port) {
238-
dtmhost = host;
238+
if (dtmhost) {
239+
free(dtmhost);
240+
dtmhost = NULL;
241+
}
242+
dtmhost = strdup(host);
239243
dtmport = port;
240244
}
241245

@@ -244,10 +248,15 @@ static DTMConn GetConnection()
244248
static DTMConn dtm = NULL;
245249
if (dtm == NULL)
246250
{
247-
dtm = DtmConnect(dtmhost, dtmport);
248-
if (dtm == NULL) {
249-
elog(ERROR, "Failed to connect to DTMD");
250-
}
251+
if (dtmhost) {
252+
dtm = DtmConnect(dtmhost, dtmport);
253+
if (dtm == NULL)
254+
{
255+
elog(ERROR, "Failed to connect to DTMD %s:%d", dtmhost, dtmport);
256+
}
257+
} else {
258+
elog(ERROR, "DTMD address not specified");
259+
}
251260
}
252261
return dtm;
253262
}

0 commit comments

Comments
 (0)