Skip to content

Commit 009149a

Browse files
committedFeb 21, 2015
Fix some memory leaks on packet sending.
1 parent 5a5854e commit 009149a

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed
 

‎src/client.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ void Client::Send(NetworkPacket* pkt)
956956
serverCommandFactoryTable[pkt->getCommand()].channel,
957957
pkt,
958958
serverCommandFactoryTable[pkt->getCommand()].reliable);
959+
delete pkt;
959960
}
960961

961962
void Client::interact(u8 action, const PointedThing& pointed)

‎src/network/connection.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ void ConnectionSendThread::connect(Address address)
17291729
m_connection->SetPeerID(PEER_ID_INEXISTENT);
17301730
NetworkPacket* pkt = new NetworkPacket(0,0);
17311731
m_connection->Send(PEER_ID_SERVER, 0, pkt, true);
1732+
delete pkt;
17321733
}
17331734

17341735
void ConnectionSendThread::disconnect()

‎src/server.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -2079,24 +2079,19 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
20792079
float maxd = far_d_nodes*BS;
20802080
v3f p_f = intToFloat(p, BS);
20812081

2082-
NetworkPacket* pkt = new NetworkPacket(TOCLIENT_REMOVENODE, 2 + 2 + 2);
2082+
NetworkPacket* pkt = new NetworkPacket(TOCLIENT_REMOVENODE, 6);
20832083
*pkt << p;
20842084

20852085
std::list<u16> clients = m_clients.getClientIDs();
20862086
for(std::list<u16>::iterator
20872087
i = clients.begin();
2088-
i != clients.end(); ++i)
2089-
{
2090-
if(far_players)
2091-
{
2088+
i != clients.end(); ++i) {
2089+
if(far_players) {
20922090
// Get player
2093-
Player *player = m_env->getPlayer(*i);
2094-
if(player)
2095-
{
2091+
if(Player *player = m_env->getPlayer(*i)) {
20962092
// If player is far away, only set modified blocks not sent
20972093
v3f player_pos = player->getPosition();
2098-
if(player_pos.getDistanceFrom(p_f) > maxd)
2099-
{
2094+
if(player_pos.getDistanceFrom(p_f) > maxd) {
21002095
far_players->push_back(*i);
21012096
continue;
21022097
}
@@ -2118,7 +2113,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
21182113
v3f p_f = intToFloat(p, BS);
21192114

21202115
std::list<u16> clients = m_clients.getClientIDs();
2121-
for(std::list<u16>::iterator
2116+
for(std::list<u16>::iterator
21222117
i = clients.begin();
21232118
i != clients.end(); ++i)
21242119
{
@@ -2139,7 +2134,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
21392134
}
21402135
}
21412136

2142-
NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ADDNODE, 0);
2137+
NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1);
21432138
m_clients.Lock();
21442139
RemoteClient* client = m_clients.lockedGetClientNoEx(*i);
21452140
if (client != 0) {

‎src/test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,8 @@ struct TestConnection: public TestBase
20102010
<< std::endl;
20112011

20122012
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
2013+
2014+
delete pkt;
20132015
}
20142016

20152017
u16 peer_id_client = 2;
@@ -2074,6 +2076,8 @@ struct TestConnection: public TestBase
20742076

20752077
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
20762078
UASSERT(peer_id == PEER_ID_SERVER);
2079+
2080+
delete pkt;
20772081
}
20782082

20792083
// Check peer handlers

0 commit comments

Comments
 (0)
Please sign in to comment.