diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-02-21 17:24:27 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-02-21 17:27:31 +0100 |
commit | 009149a073ac02dd412af3c203979157976c0dd8 (patch) | |
tree | a302fc77ef59b37fde966fb3b155989d9fa3d95b | |
parent | 5a5854ea9d0bc346b00f48f40b538b7a8d68b37a (diff) | |
download | minetest-009149a073ac02dd412af3c203979157976c0dd8.tar.gz minetest-009149a073ac02dd412af3c203979157976c0dd8.tar.bz2 minetest-009149a073ac02dd412af3c203979157976c0dd8.zip |
Fix some memory leaks on packet sending.
-rw-r--r-- | src/client.cpp | 1 | ||||
-rw-r--r-- | src/network/connection.cpp | 1 | ||||
-rw-r--r-- | src/server.cpp | 19 | ||||
-rw-r--r-- | src/test.cpp | 4 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/client.cpp b/src/client.cpp index 17661d0c1..68815e8e6 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -956,6 +956,7 @@ void Client::Send(NetworkPacket* pkt) serverCommandFactoryTable[pkt->getCommand()].channel, pkt, serverCommandFactoryTable[pkt->getCommand()].reliable); + delete pkt; } void Client::interact(u8 action, const PointedThing& pointed) diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 5c529faea..7710b1c42 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -1729,6 +1729,7 @@ void ConnectionSendThread::connect(Address address) m_connection->SetPeerID(PEER_ID_INEXISTENT); NetworkPacket* pkt = new NetworkPacket(0,0); m_connection->Send(PEER_ID_SERVER, 0, pkt, true); + delete pkt; } void ConnectionSendThread::disconnect() diff --git a/src/server.cpp b/src/server.cpp index 6c51aec4b..6a1e8085b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2079,24 +2079,19 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id, float maxd = far_d_nodes*BS; v3f p_f = intToFloat(p, BS); - NetworkPacket* pkt = new NetworkPacket(TOCLIENT_REMOVENODE, 2 + 2 + 2); + NetworkPacket* pkt = new NetworkPacket(TOCLIENT_REMOVENODE, 6); *pkt << p; std::list<u16> clients = m_clients.getClientIDs(); for(std::list<u16>::iterator i = clients.begin(); - i != clients.end(); ++i) - { - if(far_players) - { + i != clients.end(); ++i) { + if(far_players) { // Get player - Player *player = m_env->getPlayer(*i); - if(player) - { + if(Player *player = m_env->getPlayer(*i)) { // If player is far away, only set modified blocks not sent v3f player_pos = player->getPosition(); - if(player_pos.getDistanceFrom(p_f) > maxd) - { + if(player_pos.getDistanceFrom(p_f) > maxd) { far_players->push_back(*i); continue; } @@ -2118,7 +2113,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id, v3f p_f = intToFloat(p, BS); std::list<u16> clients = m_clients.getClientIDs(); - for(std::list<u16>::iterator + for(std::list<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { @@ -2139,7 +2134,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id, } } - NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ADDNODE, 0); + NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); m_clients.Lock(); RemoteClient* client = m_clients.lockedGetClientNoEx(*i); if (client != 0) { diff --git a/src/test.cpp b/src/test.cpp index 40943035d..3b7c75c6e 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -2010,6 +2010,8 @@ struct TestConnection: public TestBase << std::endl; UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0); + + delete pkt; } u16 peer_id_client = 2; @@ -2074,6 +2076,8 @@ struct TestConnection: public TestBase UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0); UASSERT(peer_id == PEER_ID_SERVER); + + delete pkt; } // Check peer handlers |