Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

NewDeleteLeaks false positive calling QTimer::singleShot with a lambda function #39338

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR40367
Status NEW
Importance P enhancement
Reported by Taylor Braun-Jones (taylor@braun-jones.org)
Reported on 2019-01-17 11:44:36 -0800
Last modified on 2020-10-31 08:01:11 -0700
Version unspecified
Hardware PC Linux
CC alexfh@google.com, dcoughlin@apple.com, djasper@google.com, eugene.zelenko@gmail.com, klimek@google.com, llvm-bugs@lists.llvm.org, Woebbeking@web.de
Fixed by commit(s)
Attachments QtSingleShotNewDeleteLeakFalsePositive.cpp (104 bytes, text/x-c++src)
Blocks
Blocked by
See also
Created attachment 21348
Minimal example showing false positive of NewDeleteLeaks check

The NewDeleteLeaks check thinks that QTimer::singleShot leaks the lambda
function object, but internally Qt reference counts the object and takes care
of deleting it.

The attached QtSingleShotNewDeleteLeakFalsePositive.cpp file demonstrates the
error:

/usr/include/x86_64-linux-gnu/qt5/QtCore/qtimer.h:154:5: error: Potential
memory leak [clang-analyzer-cplusplus.NewDeleteLeaks,-warnings-as-errors]
    }
    ^
/home/.../QtSingleShotNewDeleteLeakFalsePositive.cpp:5:5: note: Calling
'QTimer::singleShot'
    QTimer::singleShot(0, [=] {});
    ^
/usr/include/x86_64-linux-gnu/qt5/QtCore/qtimer.h:125:9: note: Calling
'QTimer::singleShot'
        singleShot(interval, defaultTypeFor(interval), nullptr, slot);
        ^
/usr/include/x86_64-linux-gnu/qt5/QtCore/qtimer.h:152:24: note: Memory is
allocated
                       new QtPrivate::QFunctorSlotObject<Func1, 0,
                       ^
/usr/include/x86_64-linux-gnu/qt5/QtCore/qtimer.h:154:5: note: Potential memory
leak
    }
    ^

This is with Qt 5.9.5 on Ubuntu 18.04. I do not see the issue on Windows with
the same Qt version.
Quuxplusone commented 5 years ago

Attached QtSingleShotNewDeleteLeakFalsePositive.cpp (104 bytes, text/x-c++src): Minimal example showing false positive of NewDeleteLeaks check