Module: check_mk
Branch: master
Commit: a0e54bfcb2fcb3d646b89c864bd1399f3daaa899
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a0e54bfcb2fcb3…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Jul 31 16:13:25 2017 +0200
Nuke one more strdup().
Change-Id: Iaaa094c31d8a52aa3f50b84d7ca01b432c691011
---
livestatus/src/LogEntry.cc | 28 +++++++++++-----------------
livestatus/src/LogEntry.h | 10 +++++-----
livestatus/src/TableLog.cc | 3 ++-
3 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index 940ca08..94cf6f0 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -60,24 +60,21 @@ LogEntry::LogEntry(MonitoringCore *mc, unsigned lineno, const char
*line)
size_t msglen = strlen(line);
while (msglen > 0 && _msg[msglen - 1] == '\n') {
_msg[--msglen] = '\0';
-
- // keep unsplitted copy of the message (needs lots of memory,
- // maybe we could optimize that one day...)
}
- _complete = strdup(_msg);
+
+ // keep unsplit copy of the message (needs lots of memory, maybe we could
+ // optimize that one day...)
+ _complete = _msg;
// pointer to options (everything after ':')
- _options = _complete;
- while (*_options != 0 && *_options != ':') {
- _options++;
+ size_t pos = _complete.find(':');
+ if (pos != string::npos) {
+ pos = _complete.find_first_not_of(' ', pos + 1);
}
- if (*_options != 0) // line contains colon
- {
- _options++; // skip ':'
- while (*_options == ' ') {
- _options++; // skip space after ':'
- }
+ if (pos == string::npos) {
+ pos = _complete.size();
}
+ _options = &_complete[pos];
// [1260722267] xxx - extract timestamp, validate message
if (msglen < 13 || _msg[0] != '[' || _msg[11] != ']') {
@@ -98,10 +95,7 @@ LogEntry::LogEntry(MonitoringCore *mc, unsigned lineno, const char
*line)
// rest is Class::INFO
}
-LogEntry::~LogEntry() {
- free(_msg);
- free(_complete);
-}
+LogEntry::~LogEntry() { free(_msg); }
bool LogEntry::assign(Param par, char **scan) {
switch (par) {
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index ee222f8..0e6f165 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -80,11 +80,11 @@ public:
time_t _time;
Class _logclass;
LogEntryType _type;
- char *_complete; // copy of complete unsplit message
- char *_options; // points into _complete after ':'
- char *_text; // points into msg
- char *_host_name; // points into msg or is 0
- char *_svc_desc; // points into msg or is 0
+ std::string _complete; // copy of complete unsplit message
+ const char *_options; // points into _complete after ':'
+ char *_text; // points into msg
+ char *_host_name; // points into msg or is 0
+ char *_svc_desc; // points into msg or is 0
const char *_command_name;
char *_contact_name;
int _state;
diff --git a/livestatus/src/TableLog.cc b/livestatus/src/TableLog.cc
index 12cfeee..8f003b1 100644
--- a/livestatus/src/TableLog.cc
+++ b/livestatus/src/TableLog.cc
@@ -33,6 +33,7 @@
#include "LogEntry.h"
#include "Logfile.h"
#include "OffsetIntColumn.h"
+#include "OffsetSStringColumn.h"
#include "OffsetStringColumn.h"
#include "OffsetTimeColumn.h"
#include "Query.h"
@@ -67,7 +68,7 @@ TableLog::TableLog(MonitoringCore *mc, LogCache *log_cache)
"class",
"The class of the message as integer (0:info, 1:state, 2:program,
3:notification, 4:passive, 5:command)",
DANGEROUS_OFFSETOF(LogEntry, _logclass), -1, -1, -1));
- addColumn(make_unique<OffsetStringColumn>(
+ addColumn(make_unique<OffsetSStringColumn>(
"message", "The complete message line including the
timestamp",
DANGEROUS_OFFSETOF(LogEntry, _complete), -1, -1, -1));
addColumn(make_unique<OffsetStringColumn>(