From 5f6bbce4beb32bc6bc1e06f92cde56c48f946558 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 26 Jan 2015 15:21:12 +0100 Subject: Fix memory leak in qSetMessagePattern We were leaking memory in case setPattern was called multiple times Task-number: QTBUG-43893 Change-Id: Icd9c214edea064aeaeb6f92a9c62836238ccd344 Reviewed-by: Marc Mutz --- src/corelib/global/qlogging.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/corelib/global/qlogging.cpp') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 50d35a6d84..86ba082398 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -866,7 +866,7 @@ QMessagePattern::QMessagePattern() QMessagePattern::~QMessagePattern() { - for (int i = 0; literals[i] != 0; ++i) + for (int i = 0; literals[i]; ++i) delete [] literals[i]; delete [] literals; literals = 0; @@ -876,8 +876,12 @@ QMessagePattern::~QMessagePattern() void QMessagePattern::setPattern(const QString &pattern) { + if (literals) { + for (int i = 0; literals[i]; ++i) + delete [] literals[i]; + delete [] literals; + } delete [] tokens; - delete [] literals; // scanner QList lexemes; -- cgit v1.2.3 From 51ba25e0fc89882e5021bed718de91d58f7f3907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20A=C5=9F=C4=B1c=C4=B1?= Date: Wed, 24 Dec 2014 17:29:11 +0200 Subject: logging: Check if uClibc has backtrace support execinfo.h is optional in uClibc. We need to check __UCLIBC_HAS_BACKTRACE__ if uClibc is used. Change-Id: Ie28be85b0b70472df1fc4a208581bb66ad34229e Reviewed-by: Kai Koehne Reviewed-by: Thiago Macieira --- src/corelib/global/qlogging.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/corelib/global/qlogging.cpp') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 50d35a6d84..fa897d6d32 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -77,14 +77,21 @@ #endif #if !defined QT_NO_REGULAREXPRESSION && !defined(QT_BOOTSTRAPPED) -# if (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_include() && __has_include()) +# ifdef __UCLIBC__ +# if __UCLIBC_HAS_BACKTRACE__ +# define QLOGGING_HAVE_BACKTRACE +# endif +# elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_include() && __has_include()) # define QLOGGING_HAVE_BACKTRACE -# include -# include -# include # endif #endif +#ifdef QLOGGING_HAVE_BACKTRACE +# include +# include +# include +#endif + #include QT_BEGIN_NAMESPACE -- cgit v1.2.3 From 2be0d3088fc5bc52ece6b28157b28d16699ccb9b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 18 Jan 2015 14:56:21 +0100 Subject: qFormatLogMessage: optimize %{backtrace} backtrace_symbols is very slow because it tries to find the function name from the address. In order to do that it needs to do a linear search over all symbols. (Because the hash table goes the other way to find the address from the symbol name) The code is going to skip a few frames from QtCore. Since we cannot know how many, we take a few more than necessary. This patch changes the additional number of frames from 15 to 7 (Usually, there are about 5 suppressed frames). We call backtrace_symbols several times for only one frame at the time. So we are not looking up addresses we don't need after we printed the right number of frames. Calling many times backtrace_symbols means we do more malloc, but that's negligible compared to the time we save. We anyway do a lot of other allocations because of the regexp operations and such So this patch is then saving about 10 frames lookups which allow to print about 6 qDebug per miliseconds instead of only 2 when using %{backtrace depth=2} Change-Id: Ic6ece2145d53dc570c80fcb0e4455dcef6bc40cb Reviewed-by: Kai Koehne --- src/corelib/global/qlogging.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/global/qlogging.cpp') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 18b672d7ee..5f11334a82 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1154,13 +1154,13 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16)); #ifdef QLOGGING_HAVE_BACKTRACE } else if (token == backtraceTokenC) { - QVarLengthArray buffer(15 + pattern->backtraceDepth); + QVarLengthArray buffer(7 + pattern->backtraceDepth); int n = backtrace(buffer.data(), buffer.size()); if (n > 0) { - QScopedPointer strings(backtrace_symbols(buffer.data(), n)); int numberPrinted = 0; for (int i = 0; i < n && numberPrinted < pattern->backtraceDepth; ++i) { - QString trace = QString::fromLatin1(strings.data()[i]); + QScopedPointer strings(backtrace_symbols(buffer.data() + i, 1)); + QString trace = QString::fromLatin1(strings.data()[0]); // The results of backtrace_symbols looks like this: // /lib/libc.so.6(__libc_start_main+0xf3) [0x4a937413] // The offset and function name are optional. -- cgit v1.2.3