There is a destructor call of a promise with an empty state in Future<T>::then<S>() when using onComplete.
Actually, there should be only one destructor call of a promise (the copy) and not two.
Where does the promise with the empty state come from?
How is it possible to create a promise with an empty state?
Memory error can be reproduced:
auto p = createPromiseInt();
p.trySuccess(10);
auto f = p.future();
auto tmp = createPromiseInt();
f.onComplete([tmp](const Try<int> &t) {});
Without capturing tmp, everything works fine.
The fix is actually very simple: Remove move constructors and assignment operators from Promise and Future. Otherwise, the shared pointer of Promise can become invalid. We do not need to move these types. They are designed to be copied.
There is a destructor call of a promise with an empty state in
Future<T>::then<S>()
when usingonComplete
. Actually, there should be only one destructor call of a promise (the copy) and not two. Where does the promise with the empty state come from? How is it possible to create a promise with an empty state?Memory error can be reproduced:
Without capturing
tmp
, everything works fine.The fix is actually very simple: Remove move constructors and assignment operators from Promise and Future. Otherwise, the shared pointer of Promise can become invalid. We do not need to move these types. They are designed to be copied.