This is an automated email from the ASF dual-hosted git repository.
wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 1cf4991b48 Eliminate leaking of HostStatusSync instances. (#11275)
1cf4991b48 is described below
commit 1cf4991b4850bce96cbad1663b266b0b5ce49994
Author: Walt Karas <[email protected]>
AuthorDate: Mon Apr 22 10:22:03 2024 -0400
Eliminate leaking of HostStatusSync instances. (#11275)
---
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 a731ba797b..550cde9913 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 9e8e7fb540..4ff46a9f9c 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()