LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 40367 - NewDeleteLeaks false positive calling QTimer::singleShot with a lambda function
Summary: NewDeleteLeaks false positive calling QTimer::singleShot with a lambda function
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: Static Analyzer (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Devin Coughlin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-17 11:44 PST by Taylor Braun-Jones
Modified: 2020-10-31 08:01 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments
Minimal example showing false positive of NewDeleteLeaks check (104 bytes, text/x-c++src)
2019-01-17 11:44 PST, Taylor Braun-Jones
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Taylor Braun-Jones 2019-01-17 11:44:36 PST
Created attachment 21348 [details]
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.