Module: check_mk
Branch: master
Commit: c2695437069419a8bf83941d744cade0fe096b19
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c2695437069419…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Wed Jan 24 10:29:35 2018 +0100
Win-agent: let std::vector manage its heap, part X
Leave dynamic memory allocation to std::vector as it does it better
than you do.
---
agents/windows/SectionManager.cc | 28 +++++++++++++---------------
agents/windows/SectionManager.h | 11 ++++++++---
agents/windows/build_version | 2 +-
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/agents/windows/SectionManager.cc b/agents/windows/SectionManager.cc
index 48cefa4..421b644 100644
--- a/agents/windows/SectionManager.cc
+++ b/agents/windows/SectionManager.cc
@@ -35,8 +35,8 @@ std::string mapSectionName(const std::string §ionName) {
} // namespace
template <>
-winperf_counter *from_string<winperf_counter *>(const WinApiAdaptor &winapi,
- const std::string &value) {
+winperf_counter from_string<winperf_counter>(const WinApiAdaptor &winapi,
+ const std::string &value) {
size_t colonIdx = value.find_last_of(":");
if (colonIdx == std::string::npos) {
fprintf(stderr,
@@ -45,25 +45,23 @@ winperf_counter *from_string<winperf_counter *>(const
WinApiAdaptor &winapi,
value.c_str());
exit(1);
}
- winperf_counter *result = new winperf_counter();
- result->name = std::string(value.begin() + colonIdx + 1, value.end());
+ std::string name(value.begin() + colonIdx + 1, value.end());
std::string base_id(value.begin(), value.begin() + colonIdx);
-
auto non_digit = std::find_if_not(base_id.begin(), base_id.end(), isdigit);
+ int id = 0;
if (non_digit == base_id.end()) {
- result->id = std::stoi(base_id);
+ id = std::stoi(base_id);
} else {
- result->id = resolveCounterName(winapi, base_id);
- if (result->id == -1) {
- delete result;
+ id = resolveCounterName(winapi, base_id);
+ if (id == -1) {
throw StringConversionError(
"No matching performance counter id found for " + value);
}
}
- return result;
+ return {id, name};
}
SectionManager::SectionManager(Configuration &config,
@@ -120,11 +118,11 @@ bool SectionManager::useRealtimeMonitoring() const {
}
void SectionManager::loadDynamicSections() {
- for (winperf_counter *counter : *_winperf_counters) {
- if (counter->id != -1) {
- addSection((new SectionWinperf(counter->name.c_str(), _env, _logger,
- _winapi))
- ->withBase(counter->id));
+ for (const auto &counter : *_winperf_counters) {
+ if (counter.id != -1) {
+ addSection(
+ (new SectionWinperf(counter.name, _env, _logger, _winapi))
+ ->withBase(counter.id));
}
}
}
diff --git a/agents/windows/SectionManager.h b/agents/windows/SectionManager.h
index b6424ef..3b5b0d3 100644
--- a/agents/windows/SectionManager.h
+++ b/agents/windows/SectionManager.h
@@ -36,13 +36,18 @@ class WinApiAdaptor;
// Configuration for section [winperf]
struct winperf_counter {
+ winperf_counter(int id_, const std::string &name_) : id(id_), name(name_) {}
int id;
std::string name;
};
+inline std::ostream &operator<<(std::ostream &out, const winperf_counter
&wpc) {
+ return out << "(id = " << wpc.id << ", name = "
<< wpc.name << ")";
+}
+
template <>
-winperf_counter *from_string<winperf_counter *>(const WinApiAdaptor &winapi,
- const std::string &value);
+winperf_counter from_string<winperf_counter>(const WinApiAdaptor &winapi,
+ const std::string &value);
std::ostream &operator<<(std::ostream &out,
const std::pair<std::string, std::string> &value);
@@ -88,7 +93,7 @@ private:
_realtime_sections;
KeyedListConfigurable<std::string> _script_local_includes;
KeyedListConfigurable<std::string> _script_plugin_includes;
- ListConfigurable<std::vector<winperf_counter *>> _winperf_counters;
+ ListConfigurable<std::vector<winperf_counter>> _winperf_counters;
const Environment &_env;
Logger *_logger;
const WinApiAdaptor &_winapi;
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 5caf80a..dc3b4b1 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3074
+3076