mirror of
https://github.com/oatpp/oatpp.git
synced 2025-02-17 17:29:57 +08:00
Fixed memory leak in move assignement operators
This commit is contained in:
parent
2b6a90f601
commit
4f1e0b81d9
@ -168,23 +168,16 @@ CoroutineStarter::CoroutineStarter(CoroutineStarter&& other)
|
||||
}
|
||||
|
||||
CoroutineStarter::~CoroutineStarter() {
|
||||
if(m_first != nullptr) {
|
||||
auto curr = m_first;
|
||||
while(curr != nullptr) {
|
||||
AbstractCoroutine* next = nullptr;
|
||||
if(curr->m_parentReturnAction.m_type == Action::TYPE_COROUTINE) {
|
||||
next = curr->m_parentReturnAction.m_data.coroutine;
|
||||
}
|
||||
delete curr;
|
||||
curr = next;
|
||||
}
|
||||
}
|
||||
freeCoroutines();
|
||||
}
|
||||
|
||||
/*
|
||||
* Move assignment operator.
|
||||
*/
|
||||
CoroutineStarter& CoroutineStarter::operator=(CoroutineStarter&& other) {
|
||||
if (this == std::addressof(other)) return *this;
|
||||
|
||||
freeCoroutines();
|
||||
m_first = other.m_first;
|
||||
m_last = other.m_last;
|
||||
other.m_first = nullptr;
|
||||
@ -216,6 +209,21 @@ CoroutineStarter& CoroutineStarter::next(CoroutineStarter&& starter) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CoroutineStarter::freeCoroutines()
|
||||
{
|
||||
if (m_first != nullptr) {
|
||||
auto curr = m_first;
|
||||
while (curr != nullptr) {
|
||||
AbstractCoroutine* next = nullptr;
|
||||
if (curr->m_parentReturnAction.m_type == Action::TYPE_COROUTINE) {
|
||||
next = curr->m_parentReturnAction.m_data.coroutine;
|
||||
}
|
||||
delete curr;
|
||||
curr = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CoroutineHandle
|
||||
|
||||
|
@ -341,6 +341,11 @@ class CoroutineStarter {
|
||||
private:
|
||||
AbstractCoroutine* m_first;
|
||||
AbstractCoroutine* m_last;
|
||||
|
||||
private:
|
||||
|
||||
void freeCoroutines();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -686,6 +691,9 @@ public:
|
||||
* Move assignment operator.
|
||||
*/
|
||||
StarterForResult& operator=(StarterForResult&& other) {
|
||||
if (this == std::addressof(other)) return *this;
|
||||
|
||||
delete m_coroutine;
|
||||
m_coroutine = other.m_coroutine;
|
||||
other.m_coroutine = nullptr;
|
||||
return *this;
|
||||
|
Loading…
Reference in New Issue
Block a user