Skip to content

Commit 3b6a368

Browse files
mkmvzlbsteakhal
authored andcommitted
[analyzer] Fix QTimer::singleShot NewDeleteLeaks false positive
Fixes #39713 fferential Revision: https://reviews.llvm.org/D150552
1 parent 0ee2245 commit 3b6a368

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,11 @@ bool MallocChecker::mayFreeAnyEscapedMemoryOrIsModeledExplicitly(
32593259
return true;
32603260
}
32613261

3262+
if (FName == "singleShotImpl" &&
3263+
FD->getQualifiedNameAsString() == "QTimer::singleShotImpl") {
3264+
return true;
3265+
}
3266+
32623267
// Handle cases where we know a buffer's /address/ can escape.
32633268
// Note that the above checks handle some special cases where we know that
32643269
// even though the address escapes, it's still our responsibility to free the

clang/test/Analysis/Inputs/qt-simulator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct QSlotObjectBase {};
66

77
namespace Qt {
88
enum ConnectionType {};
9+
enum TimerType {};
910
}
1011

1112
struct QMetaObject {
@@ -31,3 +32,8 @@ struct QCoreApplication : public QObject {
3132
};
3233

3334
struct QApplication : public QCoreApplication {};
35+
36+
struct QTimer {
37+
static void singleShotImpl(int, Qt::TimerType, const QObject *,
38+
QtPrivate::QSlotObjectBase *);
39+
};

clang/test/Analysis/qt_malloc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ void connect(QObject *obj) {
1919
new QtPrivate::QSlotObjectBase(), (Qt::ConnectionType)0,
2020
nullptr, nullptr);
2121
}
22+
23+
void singleShot(QTimer *timer) {
24+
timer->singleShotImpl(0, (Qt::TimerType)0, nullptr,
25+
new QtPrivate::QSlotObjectBase());
26+
}

0 commit comments

Comments
 (0)