[Pkg-owncloud-commits] [owncloud-client] 41/83: Fix crash at exit when there is a log after the Logger has been destroyed

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat May 31 11:31:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 50ce0f9681638176aa6a7cf0edd9c482a7b07e2f
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Mon May 26 13:01:29 2014 +0200

    Fix crash at exit when there is a log after the Logger has been destroyed
    
    Use a proper static Logger instead of allocating one,  and cleanup
    the QTMessageLogger when it is destroyed
---
 src/mirall/logger.cpp | 33 ++++++++++++---------------------
 src/mirall/logger.h   |  8 +++-----
 2 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/src/mirall/logger.cpp b/src/mirall/logger.cpp
index 6c85619..0bc8d1c 100644
--- a/src/mirall/logger.cpp
+++ b/src/mirall/logger.cpp
@@ -27,6 +27,9 @@ static void mirallLogCatcher(QtMsgType type, const char *msg)
   // qDebug() exports to local8Bit, which is not always UTF-8
   Logger::instance()->mirallLog( QString::fromLocal8Bit(msg) );
 }
+static void qInstallMessageHandler(QtMsgHandler h) {
+    qInstallMsgHandler(h);
+}
 #else
 static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QString &message) {
     Q_UNUSED(ctx);
@@ -38,35 +41,23 @@ static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QSt
 }
 #endif
 
-Logger* Logger::_instance=0;
-
-Logger::Logger( QObject* parent)
-: QObject(parent),
-  _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
+Logger *Logger::instance()
 {
+    static Logger log;
+    return &log;
 }
 
-Logger *Logger::instance()
+Logger::Logger( QObject* parent) : QObject(parent),
+  _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
 {
-    if( !Logger::_instance ) {
-        Logger::_instance = new Logger;
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-        qInstallMsgHandler( mirallLogCatcher );
-#else
-        qInstallMessageHandler(mirallLogCatcher);
-#endif
-    }
-    return Logger::_instance;
+    qInstallMessageHandler(mirallLogCatcher);
 }
 
-void Logger::destroy()
-{
-    if( Logger::_instance ) {
-        delete Logger::_instance;
-        Logger::_instance = 0;
-    }
+Logger::~Logger() {
+    qInstallMessageHandler(0);
 }
 
+
 void Logger::postGuiLog(const QString &title, const QString &message)
 {
     emit guiLog(title, message);
diff --git a/src/mirall/logger.h b/src/mirall/logger.h
index 035ed62..8e4fdbe 100644
--- a/src/mirall/logger.h
+++ b/src/mirall/logger.h
@@ -41,6 +41,7 @@ class OWNCLOUDSYNC_EXPORT Logger : public QObject
 {
   Q_OBJECT
 public:
+
   void log(Log log);
 
   static void csyncLog( const QString& message );
@@ -49,7 +50,6 @@ public:
   const QList<Log>& logs() const {return _logs;}
 
   static Logger* instance();
-  static void destroy();
 
   void postGuiLog(const QString& title, const QString& message);
   void postOptionalGuiLog(const QString& title, const QString& message);
@@ -69,14 +69,12 @@ signals:
 public slots:
   void enterNextLogFile();
 
-protected:
+private:
   Logger(QObject* parent=0);
+  ~Logger();
   QList<Log> _logs;
   bool       _showTime;
   bool       _doLogging;
-
-  static Logger* _instance;
-
   QFile       _logFile;
   bool        _doFileFlush;
   int         _logExpire;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list