From e01c4db702c9ef93483a14b49683319d43816ab6 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 23 Jan 2022 00:16:09 +0300 Subject: [PATCH] Add paranoic if()s to prevent accidental double free of etcd_watch_ws --- src/etcd_state_client.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/etcd_state_client.cpp b/src/etcd_state_client.cpp index a721b51c..582a70b7 100644 --- a/src/etcd_state_client.cpp +++ b/src/etcd_state_client.cpp @@ -286,8 +286,11 @@ void etcd_state_client_t::start_etcd_watcher() { fprintf(stderr, "Revisions before %lu were compacted by etcd, reloading state\n", data["result"]["compact_revision"].uint64_value()); - http_close(etcd_watch_ws); - etcd_watch_ws = NULL; + if (etcd_watch_ws) + { + http_close(etcd_watch_ws); + etcd_watch_ws = NULL; + } etcd_watch_revision = 0; on_reload_hook(); } @@ -343,8 +346,11 @@ void etcd_state_client_t::start_etcd_watcher() } else fprintf(stderr, "Disconnected from etcd\n"); - http_close(etcd_watch_ws); - etcd_watch_ws = NULL; + if (etcd_watch_ws) + { + http_close(etcd_watch_ws); + etcd_watch_ws = NULL; + } if (etcd_watches_initialised == 0) { // Connection not established, retry in @@ -410,8 +416,11 @@ void etcd_state_client_t::start_etcd_watcher() { fprintf(stderr, "Websocket ping failed, disconnecting from etcd %s\n", selected_etcd_address.c_str()); } - http_close(etcd_watch_ws); - etcd_watch_ws = NULL; + if (etcd_watch_ws) + { + http_close(etcd_watch_ws); + etcd_watch_ws = NULL; + } start_etcd_watcher(); } else