Skip to content

Commit

Permalink
Fix coroutine frame leak upon assigning to awaitable (drogonframework…
Browse files Browse the repository at this point in the history
  • Loading branch information
marty1885 authored May 12, 2021
1 parent 2c53cf0 commit 0e70be0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/inc/drogon/utils/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ struct [[nodiscard]] Task
Task &operator=(const Task &) = delete;
Task &operator=(Task &&other)
{
if (std::addressof(other) == this)
return *this;
if (coro_)
coro_.destroy();

coro_ = other.coro_;
other.coro_ = nullptr;
return *this;
Expand Down Expand Up @@ -268,6 +273,11 @@ struct [[nodiscard]] Task<void>
Task &operator=(const Task &) = delete;
Task &operator=(Task &&other)
{
if (std::addressof(other) == this)
return *this;
if (coro_)
coro_.destroy();

coro_ = other.coro_;
other.coro_ = nullptr;
return *this;
Expand Down Expand Up @@ -533,6 +543,7 @@ auto sync_wait(AWAIT &&await)
exception_ptr = std::current_exception();
}
flag = true;
cv.notify_one();
}();

std::unique_lock lk(mtx);
Expand Down

0 comments on commit 0e70be0

Please sign in to comment.