diff options
author | rubidium <rubidium@openttd.org> | 2009-01-22 10:09:56 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-01-22 10:09:56 +0000 |
commit | 4f5a8b15edea385f5eadbe9bb40927d07576a61d (patch) | |
tree | 9407b6f5d2c57ed543f7d9315bb6b15169351ab8 /src/network | |
parent | 92b9ff3f9660fc2a5ac154a762f7568e40c97ad4 (diff) | |
download | openttd-4f5a8b15edea385f5eadbe9bb40927d07576a61d.tar.xz |
(svn r15206) -Fix [FS#2567]: memory corruption due to not properly cleanup up the mess when cancelling a download
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/tcp.cpp | 9 | ||||
-rw-r--r-- | src/network/core/tcp.h | 1 | ||||
-rw-r--r-- | src/network/core/tcp_content.cpp | 6 | ||||
-rw-r--r-- | src/network/core/tcp_content.h | 1 | ||||
-rw-r--r-- | src/network/network_content_gui.cpp | 5 |
5 files changed, 13 insertions, 9 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index 9c58af2c0..963257847 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -20,7 +20,14 @@ NetworkTCPSocketHandler::NetworkTCPSocketHandler(SOCKET s) : NetworkTCPSocketHandler::~NetworkTCPSocketHandler() { + this->CloseConnection(); + if (this->sock != INVALID_SOCKET) closesocket(this->sock); + this->sock = INVALID_SOCKET; +} + +NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection() +{ this->writable = false; this->has_quit = true; @@ -33,7 +40,7 @@ NetworkTCPSocketHandler::~NetworkTCPSocketHandler() delete this->packet_recv; this->packet_recv = NULL; - this->sock = INVALID_SOCKET; + return NETWORK_RECV_STATUS_OKAY; } /** diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index 962ea45e5..90edba014 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -22,6 +22,7 @@ private: public: bool writable; ///< Can we write to this socket? + virtual NetworkRecvStatus CloseConnection(); void Send_Packet(Packet *packet); bool Send_Packets(); bool IsPacketQueueEmpty(); diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp index 32054a1e2..7596cced8 100644 --- a/src/network/core/tcp_content.cpp +++ b/src/network/core/tcp_content.cpp @@ -50,12 +50,6 @@ bool ContentInfo::IsValid() const 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() { CloseConnection(); diff --git a/src/network/core/tcp_content.h b/src/network/core/tcp_content.h index 4d304017a..26f5878ad 100644 --- a/src/network/core/tcp_content.h +++ b/src/network/core/tcp_content.h @@ -102,7 +102,6 @@ struct ContentInfo { class NetworkContentSocketHandler : public NetworkTCPSocketHandler { protected: struct sockaddr_in client_addr; ///< The address we're connected to. - NetworkRecvStatus CloseConnection(); virtual void Close(); /** diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 8b930168a..bac705886 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -136,7 +136,10 @@ public: 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) |