mirror of https://github.com/OpenTTD/OpenTTD
(svn r15206) -Fix [FS#2567]: memory corruption due to not properly cleanup up the mess when cancelling a download
parent
92b9ff3f96
commit
4f5a8b15ed
|
@ -20,7 +20,14 @@ NetworkTCPSocketHandler::NetworkTCPSocketHandler(SOCKET s) :
|
||||||
|
|
||||||
NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
|
NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
|
||||||
{
|
{
|
||||||
|
this->CloseConnection();
|
||||||
|
|
||||||
if (this->sock != INVALID_SOCKET) closesocket(this->sock);
|
if (this->sock != INVALID_SOCKET) closesocket(this->sock);
|
||||||
|
this->sock = INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection()
|
||||||
|
{
|
||||||
this->writable = false;
|
this->writable = false;
|
||||||
this->has_quit = true;
|
this->has_quit = true;
|
||||||
|
|
||||||
|
@ -33,7 +40,7 @@ NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
|
||||||
delete this->packet_recv;
|
delete this->packet_recv;
|
||||||
this->packet_recv = NULL;
|
this->packet_recv = NULL;
|
||||||
|
|
||||||
this->sock = INVALID_SOCKET;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,7 @@ private:
|
||||||
public:
|
public:
|
||||||
bool writable; ///< Can we write to this socket?
|
bool writable; ///< Can we write to this socket?
|
||||||
|
|
||||||
|
virtual NetworkRecvStatus CloseConnection();
|
||||||
void Send_Packet(Packet *packet);
|
void Send_Packet(Packet *packet);
|
||||||
bool Send_Packets();
|
bool Send_Packets();
|
||||||
bool IsPacketQueueEmpty();
|
bool IsPacketQueueEmpty();
|
||||||
|
|
|
@ -50,12 +50,6 @@ bool ContentInfo::IsValid() const
|
||||||
return this->state < ContentInfo::INVALID && this->type >= CONTENT_TYPE_BEGIN && this->type < CONTENT_TYPE_END;
|
return this->state < ContentInfo::INVALID && this->type >= CONTENT_TYPE_BEGIN && this->type < CONTENT_TYPE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus NetworkContentSocketHandler::CloseConnection()
|
|
||||||
{
|
|
||||||
this->has_quit = true;
|
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkContentSocketHandler::Close()
|
void NetworkContentSocketHandler::Close()
|
||||||
{
|
{
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
|
|
|
@ -102,7 +102,6 @@ struct ContentInfo {
|
||||||
class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
|
class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
|
||||||
protected:
|
protected:
|
||||||
struct sockaddr_in client_addr; ///< The address we're connected to.
|
struct sockaddr_in client_addr; ///< The address we're connected to.
|
||||||
NetworkRecvStatus CloseConnection();
|
|
||||||
virtual void Close();
|
virtual void Close();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -136,7 +136,10 @@ public:
|
||||||
|
|
||||||
virtual void OnClick(Point pt, int widget)
|
virtual void OnClick(Point pt, int widget)
|
||||||
{
|
{
|
||||||
if (widget == NCDSWW_CANCELOK) delete this;
|
if (widget == NCDSWW_CANCELOK && this->downloaded_bytes != this->total_bytes) {
|
||||||
|
_network_content_client.Close();
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes)
|
virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes)
|
||||||
|
|
Loading…
Reference in New Issue