fixed the code to call the destructor when dispoing an object with mmgr
This commit is contained in:
@ -47,9 +47,9 @@ void Mmgr::free_mem (mmgr_t* mmgr, void* ptr) QSE_CPP_NOEXCEPT
|
||||
((Mmgr*)mmgr->ctx)->freeMem (ptr);
|
||||
}
|
||||
|
||||
void* Mmgr::callocate (qse_size_t n, bool raise_exception)
|
||||
void* Mmgr::callocate (qse_size_t n, bool raise_exception) throw(MemoryError)
|
||||
{
|
||||
void* ptr = this->allocate (n, raise_exception);
|
||||
void* ptr = this->allocate(n, raise_exception);
|
||||
QSE_MEMSET (ptr, 0, n);
|
||||
return ptr;
|
||||
}
|
||||
@ -70,7 +70,7 @@ void Mmgr::setDFL (Mmgr* mmgr) QSE_CPP_NOEXCEPT
|
||||
QSE_END_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
void* operator new (qse_size_t size, QSE::Mmgr* mmgr)
|
||||
void* operator new (qse_size_t size, QSE::Mmgr* mmgr) throw(QSE::Mmgr::MemoryError)
|
||||
{
|
||||
return mmgr->allocate (size);
|
||||
}
|
||||
@ -84,7 +84,7 @@ void operator delete (void* ptr, QSE::Mmgr* mmgr)
|
||||
mmgr->dispose (ptr);
|
||||
}
|
||||
|
||||
void* operator new (qse_size_t size, QSE::Mmgr* mmgr, void* existing_ptr)
|
||||
void* operator new (qse_size_t size, QSE::Mmgr* mmgr, void* existing_ptr) throw(QSE::Mmgr::MemoryError)
|
||||
{
|
||||
// mmgr unused. i put it in the parameter list to make this function
|
||||
// less conflicting with the stock ::operator new() that doesn't allocate.
|
||||
|
@ -118,7 +118,8 @@ void TcpServer::free_all_listeners () QSE_CPP_NOEXCEPT
|
||||
qse_mux_delete (this->listener_list.mux, &evt);
|
||||
|
||||
lp->close ();
|
||||
this->getMmgr()->dispose(lp); //delete lp;
|
||||
|
||||
QSE_CPP_DELETE_WITH_MMGR(lp, Listener, this->getMmgr()); // delete lp
|
||||
}
|
||||
|
||||
if (this->listener_list.mux_pipe[0] >= 0)
|
||||
@ -190,7 +191,7 @@ void TcpServer::dispatch_mux_event (qse_mux_t* mux, const qse_mux_evt_t* evt) QS
|
||||
// allocating the client object before accept is
|
||||
// a bit awkward. but socket.accept() can be passed
|
||||
// the socket field inside the client object.
|
||||
try { client = new(server->getMmgr()) Client (lsck); }
|
||||
try { client = new(server->getMmgr()) Client(lsck); }
|
||||
catch (...)
|
||||
{
|
||||
// memory alloc failed. accept the connection and close it.
|
||||
@ -214,24 +215,28 @@ void TcpServer::dispatch_mux_event (qse_mux_t* mux, const qse_mux_evt_t* evt) QS
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
server->client_list.append (client);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// TODO: logging.
|
||||
QSE_CPP_DELETE_WITH_MMGR (client, Client, server->getMmgr()); // delete client
|
||||
return;
|
||||
}
|
||||
|
||||
client->setStackSize (server->thread_stack_size);
|
||||
#if defined(_WIN32)
|
||||
if (client->start(Thread::DETACHED) <= -1)
|
||||
#else
|
||||
if (client->start(0) <= -1)
|
||||
#endif
|
||||
{
|
||||
server->getMmgr()->dispose (client); //delete client;
|
||||
return;
|
||||
}
|
||||
|
||||
try { server->client_list.append (client); }
|
||||
catch (...)
|
||||
{
|
||||
// TODO: logging.
|
||||
server->getMmgr()->dispose (client); //delete client;
|
||||
// don't delete the client object here. as it's int the client_list,
|
||||
// this->delete_dead_clients() should delete this client later.
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -370,8 +375,6 @@ int TcpServer::start (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
this->server_serving = true;
|
||||
this->setStopRequested (false);
|
||||
|
||||
Client* client = QSE_NULL;
|
||||
|
||||
try
|
||||
{
|
||||
if (this->setup_listeners(addrs) <= -1)
|
||||
@ -399,12 +402,10 @@ int TcpServer::start (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
}
|
||||
|
||||
this->delete_all_clients ();
|
||||
if (client != QSE_NULL) this->getMmgr()->dispose (client); // delete client;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
this->delete_all_clients ();
|
||||
if (client != QSE_NULL) this->getMmgr()->dispose (client); //delete client;
|
||||
|
||||
this->setErrorCode (E_EEXCEPT);
|
||||
this->server_serving = false;
|
||||
@ -451,8 +452,7 @@ void TcpServer::delete_dead_clients () QSE_CPP_NOEXCEPT
|
||||
#if !defined(_WIN32)
|
||||
p->join ();
|
||||
#endif
|
||||
|
||||
this->getMmgr()->dispose (p); //delete p;
|
||||
QSE_CPP_DELETE_WITH_MMGR (p, Client, this->getMmgr()); // delete p
|
||||
np2 = np; np = np->getNextNode();
|
||||
this->client_list.remove (np2);
|
||||
continue;
|
||||
@ -484,7 +484,7 @@ void TcpServer::delete_all_clients () QSE_CPP_NOEXCEPT
|
||||
#else
|
||||
p->join ();
|
||||
#endif
|
||||
this->getMmgr()->dispose (p); //delete p;
|
||||
QSE_CPP_DELETE_WITH_MMGR (p, Client, this->getMmgr()); // delete p
|
||||
np2 = np; np = np->getNextNode();
|
||||
this->client_list.remove (np2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user