diff --git a/mythtv/libs/libmythbase/logging.cpp b/mythtv/libs/libmythbase/logging.cpp index a71bfceacb3..bd6c5011261 100644 --- a/mythtv/libs/libmythbase/logging.cpp +++ b/mythtv/libs/libmythbase/logging.cpp @@ -142,8 +142,8 @@ LoggingItem::LoggingItem() LoggingItem::LoggingItem(const char *_file, const char *_function, int _line, LogLevel_t _level, LoggingType _type) : m_threadId((uint64_t)(QThread::currentThreadId())), - m_line(_line), m_type(_type), m_level(_level), m_file(_file), - m_function(_function), m_threadName(NULL) + m_line(_line), m_type(_type), m_level(_level), + m_file(strdup(_file)), m_function(strdup(_function)), m_threadName(NULL) { loggingGetTimeStamp(&m_epoch, &m_usec); @@ -153,6 +153,26 @@ LoggingItem::LoggingItem(const char *_file, const char *_function, refcount.ref(); } +LoggingItem::~LoggingItem() +{ + if (m_file) + free((void *)m_file); + + if (m_function) + free((void *)m_function); + + if (m_threadName) + free(m_threadName); + + if (m_appName) + free((void *)m_appName); + + if (m_table) + free((void *)m_table); + + if (m_logFile) + free((void *)m_logFile); +} QByteArray LoggingItem::toByteArray(void) { @@ -176,8 +196,8 @@ char *LoggingItem::getThreadName(void) QMutexLocker locker(&logThreadMutex); char *name = logThreadHash.value(m_threadId, (char *)unknown); - m_threadName = name; - return name; + m_threadName = strdup(name); + return m_threadName; } /// \brief Get the thread ID of the thread that produced the LoggingItem @@ -664,8 +684,6 @@ void LoggingItem::deleteItem(void) { if (!refcount.deref()) { - if (m_threadName) - free(m_threadName); item_count.deref(); this->deleteLater(); } diff --git a/mythtv/libs/libmythbase/logging.h b/mythtv/libs/libmythbase/logging.h index bb9fa2a2efe..998d5050f62 100644 --- a/mythtv/libs/libmythbase/logging.h +++ b/mythtv/libs/libmythbase/logging.h @@ -106,19 +106,19 @@ class LoggingItem: public QObject void setLevel(const int val) { m_level = (LogLevel_t)val; }; void setFacility(const int val) { m_facility = val; }; void setEpoch(const qlonglong val) { m_epoch = val; }; - void setFile(const QString val) + void setFile(const QString &val) { m_file = strdup(val.toLocal8Bit().constData()); }; - void setFunction(const QString val) + void setFunction(const QString &val) { m_function = strdup(val.toLocal8Bit().constData()); }; - void setThreadName(const QString val) + void setThreadName(const QString &val) { m_threadName = strdup(val.toLocal8Bit().constData()); }; - void setAppName(const QString val) + void setAppName(const QString &val) { m_appName = strdup(val.toLocal8Bit().constData()); }; - void setTable(const QString val) + void setTable(const QString &val) { m_table = strdup(val.toLocal8Bit().constData()); }; - void setLogFile(const QString val) + void setLogFile(const QString &val) { m_logFile = strdup(val.toLocal8Bit().constData()); }; - void setMessage(const QString val) + void setMessage(const QString &val) { strncpy(m_message, val.toLocal8Bit().constData(), LOGLINE_MAX); m_message[LOGLINE_MAX] = '\0'; @@ -154,6 +154,7 @@ class LoggingItem: public QObject LoggingItem(); LoggingItem(const char *_file, const char *_function, int _line, LogLevel_t _level, LoggingType _type); + ~LoggingItem(); }; /// \brief The logging thread that consumes the logging queue and dispatches diff --git a/mythtv/libs/libmythbase/loggingserver.cpp b/mythtv/libs/libmythbase/loggingserver.cpp index 05053568f52..a71a85e24e7 100644 --- a/mythtv/libs/libmythbase/loggingserver.cpp +++ b/mythtv/libs/libmythbase/loggingserver.cpp @@ -135,7 +135,7 @@ LoggerBase::~LoggerBase() /// \brief FileLogger constructor /// \param filename Filename of the logfile. FileLogger::FileLogger(const char *filename) : - LoggerBase(filename), m_opened(false), m_fd(-1) + LoggerBase(filename), m_opened(false), m_fd(-1), m_zmqSock(NULL) { m_fd = open(filename, O_WRONLY|O_CREAT|O_APPEND, 0664); m_opened = (m_fd != -1); @@ -247,7 +247,8 @@ void FileLogger::setupZMQSocket(void) #ifndef _WIN32 /// \brief SyslogLogger constructor /// \param facility Syslog facility to use in logging -SyslogLogger::SyslogLogger() : LoggerBase(NULL), m_opened(false) +SyslogLogger::SyslogLogger() : + LoggerBase(NULL), m_opened(false), m_zmqSock(NULL) { openlog(NULL, LOG_NDELAY, 0 ); m_opened = true; @@ -308,7 +309,8 @@ void SyslogLogger::setupZMQSocket(void) // Windows doesn't have syslog support -SyslogLogger::SyslogLogger() : LoggerBase(NULL), m_opened(false) +SyslogLogger::SyslogLogger() : + LoggerBase(NULL), m_opened(false), m_zmqSock(NULL) { } @@ -333,7 +335,8 @@ const int DatabaseLogger::kMinDisabledTime = 1000; /// \brief DatabaseLogger constructor /// \param table C-string of the database table to log to DatabaseLogger::DatabaseLogger(const char *table) : - LoggerBase(table), m_opened(false), m_loggingTableExists(false) + LoggerBase(table), m_opened(false), m_loggingTableExists(false), + m_zmqSock(NULL) { m_query = QString( "INSERT INTO %1 "