Add paranoic if()s to prevent accidental double free of etcd_watch_ws

non-odp-rdma
Vitaliy Filippov 2022-01-23 00:16:09 +03:00
parent a5cf06acd0
commit e01c4db702
1 changed files with 15 additions and 6 deletions

View File

@ -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 <etcd_quick_timeout>
@ -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