-
-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UB when passing a temporary lambda to a delegate #1019
Comments
Deleting the rvalue reference constructor seems to do the trick and doesn't cause any problems with the unit tests, except for the ones that this change is designed to fix. So even some of the unit tests were relying on UB! |
Out of curiosity, are you building the tests with ASAN enabled? |
I sometimes run the Linux unit test builds with |
I don't run the sanitizer option all of the time as the tests can take a very long time to run. |
Wait, maybe I'm missing something, the test suite seems super fast.
Granted, it's not as fast as without sanitizer enabled, but still impressively fast given the number of tests.
Unsure why ASAN didn't complain about the lambdas in this case. |
I run the sanitizer with optimisations enabled. Plus the script runs the tests with various setups, for GCC and Clang. I'm also running the Linux tests under Windows WSL2. |
We have a DMA driver that allows you to pass a lambda callback to call when the transfer has completed. When compiling for host with ASAN enabled we noticed that when passing a temporary lambda that captures:
ASAN will complain about stack use after scope end. If we extract the lambda to a variable it works just fine:
It makes sense since
delegate
only references the callable passed to it, and when the callable goes out of scope it has to yolo it. I did some quick testing and deleting the constructor that accepts a moved lambda prevents you from making this mistake.I don't know if it's the right or wrong solution to this but it does make sense that you don't want to reference a moved lambda if you don't want to take ownership of it.
The text was updated successfully, but these errors were encountered: