From 0c711e1a32249a7ab9b7f6cfbb47f3fc80084342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 26 Aug 2021 20:10:30 +0200 Subject: [PATCH] Prevent a crash while syncing proxysql_servers in Cluster --- lib/ProxySQL_Cluster.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index 156f5ff7c..98aacc6f5 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -693,11 +693,15 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { ) { if (v->diff_check >= diff_ps) { proxy_info("Cluster: detected a peer %s:%d with proxysql_servers version %llu, epoch %llu, diff_check %u. Own version: %llu, epoch: %llu. Proceeding with remote sync\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch); + // v->checksum will be destroyed when calling pull_proxysql_servers_from_peer() + // thus we need to copy it now + char *old_checksum = strdup(v->checksum); GloProxyCluster->pull_proxysql_servers_from_peer(); - if (strncmp(v->checksum, GloVars.checksums_values.proxysql_servers.checksum, 20)==0) { + if (strncmp(old_checksum, GloVars.checksums_values.proxysql_servers.checksum, 20)==0) { // we copied from the remote server, let's also copy the same epoch GloVars.checksums_values.proxysql_servers.epoch = v->epoch; } + free(old_checksum); } } if ((v->epoch == own_epoch) && v->diff_check && ((v->diff_check % (diff_ps*10)) == 0)) {