This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 0a9b9f8140d44101dfe703d064602e3c0d1c0f60 Author: Walt Karas <[email protected]> AuthorDate: Mon Apr 22 10:22:03 2024 -0400 Eliminate leaking of HostStatusSync instances. (#11275) (cherry picked from commit 1cf4991b4850bce96cbad1663b266b0b5ce49994) --- include/proxy/HostStatus.h | 34 +++++++++++++++++++++++++--------- src/proxy/HostStatus.cc | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/proxy/HostStatus.h b/include/proxy/HostStatus.h index 436d133cf5..5772b05bdc 100644 --- a/include/proxy/HostStatus.h +++ b/include/proxy/HostStatus.h @@ -175,9 +175,29 @@ struct HostStatRec { } }; -struct HostStatusSync : public Continuation { +class HostStatusSync : public Continuation +{ +private: + HostStatusSync() + { + getHostStatusPersistentFilePath(); + + SET_HANDLER(&HostStatusSync::mainEvent); + } + + ~HostStatusSync() = default; + +public: + HostStatusSync(HostStatusSync const &) = delete; + std::string hostRecordsFile; + static HostStatusSync * + new_instance() + { + return new HostStatusSync; + } + void sync_task(); void getHostStatusPersistentFilePath() @@ -186,18 +206,14 @@ struct HostStatusSync : public Continuation { hostRecordsFile = Layout::relative_to(rundir, ts::filename::HOST_RECORDS); } -public: - HostStatusSync() - { - getHostStatusPersistentFilePath(); - - SET_HANDLER(&HostStatusSync::mainEvent); - } - + // Deletes instance. int mainEvent(int event, Event *e) { sync_task(); + + delete this; + return EVENT_DONE; } }; diff --git a/src/proxy/HostStatus.cc b/src/proxy/HostStatus.cc index 668a52e6fc..b1e0bb3463 100644 --- a/src/proxy/HostStatus.cc +++ b/src/proxy/HostStatus.cc @@ -494,7 +494,7 @@ server_set_status(std::string_view id, YAML::Node const ¶ms) // schedule a write to the persistent store. Debug("host_statuses", "updating persistent store"); - eventProcessor.schedule_imm(new HostStatusSync, ET_TASK); + eventProcessor.schedule_imm(HostStatusSync::new_instance(), ET_TASK); } catch (std::exception const &ex) { Debug("host_statuses", "Got an error HostCmdInfo decoding: %s", ex.what()); resp.errata()
