r256887 - [analyzer] Fix false warning about memory leak for QApplication::postEvent
Anna Zaks via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 5 16:32:56 PST 2016
Author: zaks
Date: Tue Jan 5 18:32:56 2016
New Revision: 256887
URL: http://llvm.org/viewvc/llvm-project?rev=256887&view=rev
Log:
[analyzer] Fix false warning about memory leak for QApplication::postEvent
According to Qt documentation Qt takes care of memory allocated for QEvent:
http://doc.qt.io/qt-4.8/qcoreapplication.html#postEvent
A patch by Evgeniy Dushistov!
Differential Revision: http://reviews.llvm.org/D14170
Added:
cfe/trunk/test/Analysis/Inputs/qt-simulator.h
cfe/trunk/test/Analysis/qt_malloc.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=256887&r1=256886&r2=256887&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Tue Jan 5 18:32:56 2016
@@ -2508,6 +2508,16 @@ bool MallocChecker::mayFreeAnyEscapedMem
return true;
}
+ if (FName == "postEvent" &&
+ FD->getQualifiedNameAsString() == "QCoreApplication::postEvent") {
+ return true;
+ }
+
+ if (FName == "postEvent" &&
+ FD->getQualifiedNameAsString() == "QCoreApplication::postEvent") {
+ return true;
+ }
+
// Handle cases where we know a buffer's /address/ can escape.
// Note that the above checks handle some special cases where we know that
// even though the address escapes, it's still our responsibility to free the
Added: cfe/trunk/test/Analysis/Inputs/qt-simulator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/qt-simulator.h?rev=256887&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/Inputs/qt-simulator.h (added)
+++ cfe/trunk/test/Analysis/Inputs/qt-simulator.h Tue Jan 5 18:32:56 2016
@@ -0,0 +1,16 @@
+#pragma clang system_header
+
+struct QObject {
+};
+
+struct QEvent {
+ enum Type { None };
+ QEvent(Type) {}
+};
+
+struct QCoreApplication : public QObject {
+ static void postEvent(QObject *receiver, QEvent *event);
+ static QCoreApplication *instance();
+};
+
+struct QApplication : public QCoreApplication {};
Added: cfe/trunk/test/Analysis/qt_malloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/qt_malloc.cpp?rev=256887&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/qt_malloc.cpp (added)
+++ cfe/trunk/test/Analysis/qt_malloc.cpp Tue Jan 5 18:32:56 2016
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus -analyzer-store=region -verify %s
+// expected-no-diagnostics
+#include "Inputs/qt-simulator.h"
+
+void send(QObject *obj)
+{
+ QEvent *e1 = new QEvent(QEvent::None);
+ static_cast<QApplication *>(QCoreApplication::instance())->postEvent(obj, e1);
+ QEvent *e2 = new QEvent(QEvent::None);
+ QCoreApplication::instance()->postEvent(obj, e2);
+ QEvent *e3 = new QEvent(QEvent::None);
+ QCoreApplication::postEvent(obj, e3);
+ QEvent *e4 = new QEvent(QEvent::None);
+ QApplication::postEvent(obj, e4);
+}
More information about the cfe-commits
mailing list