fixing some memory leaks
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13194 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
706c231691
commit
12075a19b7
@ -37,10 +37,6 @@ Event::Event(ENetEvent* event)
|
||||
type = EVENT_TYPE_MESSAGE;
|
||||
break;
|
||||
case ENET_EVENT_TYPE_NONE:
|
||||
// Typically there's no packet data, but just in
|
||||
// case test and delete it
|
||||
if(event->packet)
|
||||
enet_packet_destroy(event->packet);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
@ -58,6 +54,7 @@ Event::Event(ENetEvent* event)
|
||||
|
||||
if (m_packet)
|
||||
enet_packet_destroy(m_packet); // we got all we need, just remove the data.
|
||||
m_packet = NULL;
|
||||
|
||||
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
|
||||
peer = new STKPeer*;
|
||||
|
@ -109,8 +109,6 @@ void NetworkManager::notifyEvent(Event* event)
|
||||
|
||||
// notify for the event now.
|
||||
ProtocolManager::getInstance()->notifyEvent(event);
|
||||
|
||||
delete event; // in this case only, the event has been copied by the protocol manager
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -260,8 +260,9 @@ void ProtocolManager::update()
|
||||
{
|
||||
Log::debug("ProtocolManager", "Message is \"%s\"", event->data.c_str());
|
||||
}
|
||||
|
||||
|
||||
// because we made a copy of the event
|
||||
delete event->peer; // no more need of that
|
||||
delete event;
|
||||
}
|
||||
|
||||
|
@ -209,15 +209,20 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
}
|
||||
STKPeer* peer = *(event->peer);
|
||||
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
||||
profile->kart_name = "";
|
||||
profile->race_id = event->data.gui8(1);
|
||||
uint32_t token = event->data.gui32(3);
|
||||
uint32_t global_id = event->data.gui32(8);
|
||||
if (global_id == CurrentOnlineUser::get()->getUserID())
|
||||
{
|
||||
Log::info("ClientLobbyRoomProtocol", "The server accepted the connection.");
|
||||
|
||||
|
||||
// self profile
|
||||
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
|
||||
profile->kart_name = "";
|
||||
profile->race_id = event->data.gui8(1);
|
||||
profile->user_profile = CurrentOnlineUser::get();
|
||||
m_setup->addPlayer(profile);
|
||||
// connection token
|
||||
uint32_t token = event->data.gui32(3);
|
||||
peer->setClientServerToken(token);
|
||||
// add all players
|
||||
event->data.removeFront(12); // remove the 12 first bytes
|
||||
int remaining = event->data.size();
|
||||
@ -240,11 +245,8 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
m_setup->addPlayer(profile2);
|
||||
event->data.removeFront(7);
|
||||
}
|
||||
|
||||
|
||||
// add self
|
||||
profile->user_profile = CurrentOnlineUser::get();
|
||||
m_setup->addPlayer(profile);
|
||||
peer->setClientServerToken(token);
|
||||
m_server = *(event->peer);
|
||||
m_state = CONNECTED;
|
||||
}
|
||||
|
@ -49,13 +49,13 @@ void GetPeerAddress::update()
|
||||
if (m_state == NONE)
|
||||
{
|
||||
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("peer_id",m_peer_id);
|
||||
connector->setParameter("action","get");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("peer_id",m_peer_id);
|
||||
connector.setParameter("action","get");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
|
||||
if(result->get("success", &rec_success))
|
||||
|
@ -45,12 +45,12 @@ void HidePublicAddress::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("action","unset");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("action","unset");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
|
||||
if(result->get("success", &rec_success))
|
||||
|
@ -47,12 +47,12 @@ void QuickJoinProtocol::update()
|
||||
if (m_state == NONE)
|
||||
{
|
||||
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("action","quick-join");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("action","quick-join");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
TransportAddress* res = static_cast<TransportAddress*>(m_callback_object);
|
||||
|
||||
|
@ -47,13 +47,13 @@ void RequestConnection::update()
|
||||
{
|
||||
case NONE:
|
||||
{
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("server_id",m_server_id);
|
||||
connector->setParameter("action","request-connection");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("server_id",m_server_id);
|
||||
connector.setParameter("action","request-connection");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
|
||||
if(result->get("success", &rec_success))
|
||||
|
@ -112,14 +112,14 @@ void ServerLobbyRoomProtocol::update()
|
||||
{
|
||||
last_poll_time = Time::getRealTime();
|
||||
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("address",addr.ip);
|
||||
connector->setParameter("port",addr.port);
|
||||
connector->setParameter("action","poll-connection-requests");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("address",addr.ip);
|
||||
connector.setParameter("port",addr.port);
|
||||
connector.setParameter("action","poll-connection-requests");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
if(result->get("success", &rec_success))
|
||||
{
|
||||
|
@ -45,15 +45,15 @@ void ShowPublicAddress::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
|
||||
connector->setParameter("address",addr.ip);
|
||||
connector->setParameter("port",addr.port);
|
||||
connector->setParameter("action","set");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("address",addr.ip);
|
||||
connector.setParameter("port",addr.port);
|
||||
connector.setParameter("action","set");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
|
||||
if(result->get("success", &rec_success))
|
||||
|
@ -45,15 +45,15 @@ void StartServer::update()
|
||||
if (m_state == NONE)
|
||||
{
|
||||
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("address",addr.ip);
|
||||
connector->setParameter("port",addr.port);
|
||||
connector->setParameter("max_players",UserConfigParams::m_server_max_players);
|
||||
connector->setParameter("action","start-server");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("address",addr.ip);
|
||||
connector.setParameter("port",addr.port);
|
||||
connector.setParameter("max_players",UserConfigParams::m_server_max_players);
|
||||
connector.setParameter("action","start-server");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
|
||||
if(result->get("success", &rec_success))
|
||||
|
@ -45,14 +45,14 @@ void StopServer::update()
|
||||
if (m_state == NONE)
|
||||
{
|
||||
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector->setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector->setParameter("address",addr.ip);
|
||||
connector->setParameter("port",addr.port);
|
||||
connector->setParameter("action","stop-server");
|
||||
HTTPConnector connector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector.setParameter("id",CurrentOnlineUser::get()->getUserID());
|
||||
connector.setParameter("token",CurrentOnlineUser::get()->getToken());
|
||||
connector.setParameter("address",addr.ip);
|
||||
connector.setParameter("port",addr.port);
|
||||
connector.setParameter("action","stop-server");
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
const XMLNode * result = connector.getXMLFromPage();
|
||||
std::string rec_success;
|
||||
|
||||
if(result->get("success", &rec_success))
|
||||
|
@ -44,6 +44,7 @@ void* STKHost::receive_data(void* self)
|
||||
Event* evt = new Event(&event);
|
||||
if (event.type != ENET_EVENT_TYPE_NONE)
|
||||
NetworkManager::getInstance()->notifyEvent(evt);
|
||||
delete evt;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@ -48,16 +48,15 @@ STKPeer::STKPeer(const STKPeer& peer)
|
||||
STKPeer::~STKPeer()
|
||||
{
|
||||
if (m_peer)
|
||||
{
|
||||
m_peer = NULL;
|
||||
}
|
||||
if (m_player_profile)
|
||||
m_player_profile = NULL;
|
||||
delete m_player_profile;
|
||||
m_player_profile = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool STKPeer::connectToHost(STKHost* localhost, TransportAddress host,
|
||||
bool STKPeer::connectToHost(STKHost* localhost, TransportAddress host,
|
||||
uint32_t channel_count, uint32_t data)
|
||||
{
|
||||
ENetAddress address;
|
||||
@ -92,7 +91,7 @@ void STKPeer::disconnect()
|
||||
|
||||
void STKPeer::sendPacket(NetworkString const& data)
|
||||
{
|
||||
Log::verbose("STKPeer", "sending packet of size %d to %i.%i.%i.%i:%i",
|
||||
Log::verbose("STKPeer", "sending packet of size %d to %i.%i.%i.%i:%i",
|
||||
data.size(), (m_peer->address.host>>0)&0xff,
|
||||
(m_peer->address.host>>8)&0xff,(m_peer->address.host>>16)&0xff,
|
||||
(m_peer->address.host>>24)&0xff,m_peer->address.port);
|
||||
|
Loading…
x
Reference in New Issue
Block a user