Dushistov created this revision.
Dushistov added reviewers: Ayal, zaks.anna, dcoughlin, xazax.hun.
Dushistov added a subscriber: cfe-commits.

Recent version of clang (3.7) start complain about such code:
void send(QObject *obj)
{
        QKeyEvent *event = new QKeyEvent(QEvent::KeyRelease, Qt::Key_Tab, 
Qt::NoModifier);
        qApp->postEvent(obj, event);
}

warning: Potential leak of memory pointed to by 'event'

This is false positive, because of according to Qt documentation Qt take care 
about memory allocated for QEvent:
http://doc.qt.io/qt-4.8/qcoreapplication.html#postEvent

Because of Qt popular enought I suggest to handle postEvent case in 
MallocChecker

http://reviews.llvm.org/D14170

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2511,6 +2511,10 @@
     return true;
   }
 
+  if (FName.endswith("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


Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2511,6 +2511,10 @@
     return true;
   }
 
+  if (FName.endswith("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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to