- Fixed a memory leak when connection requests failed.
- Maybe some other (small) bugfix as well.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6574
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#include "wx/defs.h"
#endif
#include "wx/defs.h"
#endif
+#if wxUSE_SOCKETS && wxUSE_IPC
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
- if (!connection->IsKindOf(CLASSINFO(wxTCPConnection)))
- {
- delete connection;
- // and fall through to delete everything else
- }
- else
+ if (connection->IsKindOf(CLASSINFO(wxTCPConnection)))
{
connection->m_topic = topic;
connection->m_sock = client;
{
connection->m_topic = topic;
connection->m_sock = client;
client->Notify(TRUE);
return connection;
}
client->Notify(TRUE);
return connection;
}
+ else
+ {
+ delete connection;
+ // and fall through to delete everything else
+ }
- // something went wrong
+ // Something went wrong, delete everything
delete data_is;
delete data_os;
delete stream;
delete data_is;
delete data_os;
delete stream;
wxTCPConnection::~wxTCPConnection ()
{
wxTCPConnection::~wxTCPConnection ()
{
wxDELETE(m_codeci);
wxDELETE(m_codeco);
wxDELETE(m_sockstrm);
wxDELETE(m_codeci);
wxDELETE(m_codeco);
wxDELETE(m_sockstrm);
+
+ if (m_sock) m_sock->Destroy();
}
void wxTCPConnection::Compress(bool WXUNUSED(on))
}
void wxTCPConnection::Compress(bool WXUNUSED(on))
{
// Send the the disconnect message to the peer.
m_codeco->Write8(IPC_DISCONNECT);
{
// Send the the disconnect message to the peer.
m_codeco->Write8(IPC_DISCONNECT);
+ m_sock->Callback(NULL);
m_sock->Close();
return TRUE;
m_sock->Close();
return TRUE;
-void Client_OnRequest(wxSocketBase& sock, wxSocketNotify evt,
- char *cdata)
+void Client_OnRequest(wxSocketBase& sock,
+ wxSocketNotify evt,
+ char *cdata)
{
int msg = 0;
wxTCPConnection *connection = (wxTCPConnection *)cdata;
{
int msg = 0;
wxTCPConnection *connection = (wxTCPConnection *)cdata;
// The socket handler signals us that we lost the connection: destroy all.
if (evt == wxSOCKET_LOST)
{
// The socket handler signals us that we lost the connection: destroy all.
if (evt == wxSOCKET_LOST)
{
sock.Close();
connection->OnDisconnect();
return;
sock.Close();
connection->OnDisconnect();
return;
+ wxLogDebug("IPC_DISCONNECT");
+ sock.Callback(NULL);
sock.Close();
connection->OnDisconnect();
break;
sock.Close();
connection->OnDisconnect();
break;
}
void Server_OnRequest(wxSocketServer& server,
}
void Server_OnRequest(wxSocketServer& server,
- wxSocketNotify evt, char *cdata)
+ wxSocketNotify evt,
+ char *cdata)
{
wxTCPServer *ipcserv = (wxTCPServer *)cdata;
wxSocketStream *stream;
{
wxTCPServer *ipcserv = (wxTCPServer *)cdata;
wxSocketStream *stream;
if (evt != wxSOCKET_CONNECTION)
return;
if (evt != wxSOCKET_CONNECTION)
return;
- /* Accept the connection, getting a new socket */
+ // Accept the connection, getting a new socket
wxSocketBase *sock = server.Accept();
if (!sock->Ok())
wxSocketBase *sock = server.Accept();
if (!sock->Ok())
stream = new wxSocketStream(*sock);
codeci = new wxDataInputStream(*stream);
stream = new wxSocketStream(*sock);
codeci = new wxDataInputStream(*stream);
wxString topic_name;
topic_name = codeci->ReadString();
wxString topic_name;
topic_name = codeci->ReadString();
- /* Register new socket with the notifier */
wxTCPConnection *new_connection =
(wxTCPConnection *)ipcserv->OnAcceptConnection (topic_name);
wxTCPConnection *new_connection =
(wxTCPConnection *)ipcserv->OnAcceptConnection (topic_name);
- if (!new_connection->IsKindOf(CLASSINFO(wxTCPConnection)))
+ if (new_connection->IsKindOf(CLASSINFO(wxTCPConnection)))
- delete new_connection;
- codeco->Write8(IPC_FAIL);
+ // Acknowledge success
+ codeco->Write8(IPC_CONNECT);
+ new_connection->m_topic = topic_name;
+ new_connection->m_sock = sock;
+ new_connection->m_sockstrm = stream;
+ new_connection->m_codeci = codeci;
+ new_connection->m_codeco = codeco;
+ sock->Callback(Client_OnRequest);
+ sock->CallbackData((char *)new_connection);
+ sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
+ sock->Notify(TRUE);
- // Acknowledge success
- codeco->Write8(IPC_CONNECT);
- new_connection->m_topic = topic_name;
- new_connection->m_sock = sock;
- new_connection->m_sockstrm = stream;
- new_connection->m_codeci = codeci;
- new_connection->m_codeco = codeco;
- sock->Callback(Client_OnRequest);
- sock->CallbackData((char *)new_connection);
- sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
- sock->Notify(TRUE);
- }
- else
- {
- // Send failure message
- codeco->Write8(IPC_FAIL);
+ else
+ {
+ delete new_connection;
+ // and fall through to delete everything else
+ }
+
+ // Something went wrong, send failure message and delete everything
+ codeco->Write8(IPC_FAIL);
+
+ delete codeco;
+ delete codeci;
+ delete stream;
+ sock->Destroy();
+ // wxUSE_SOCKETS && wxUSE_IPC