Remove the use of a delete[] in NetPlayServer.

We just use a vector instead of a raw pointer.
This commit is contained in:
Lioncash 2014-05-29 20:09:10 -04:00
parent 3097345929
commit a3ae20fc15
1 changed files with 6 additions and 7 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <vector>
#include "Core/NetPlayServer.h"
NetPlayServer::~NetPlayServer()
@ -424,15 +426,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
PadMapping map = 0;
u8 size;
packet >> map >> size;
u8* data = new u8[size];
for (unsigned int i = 0; i < size; ++i)
std::vector<u8> data(size);
for (size_t i = 0; i < data.size(); ++i)
packet >> data[i];
// If the data is not from the correct player,
// then disconnect them.
if (m_wiimote_map[map] != player.pid)
{
delete[] data;
return 1;
}
@ -441,10 +442,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
spac << (MessageId)NP_MSG_WIIMOTE_DATA;
spac << map;
spac << size;
for (unsigned int i = 0; i < size; ++i)
spac << data[i];
delete[] data;
for (const u8& byte : data)
spac << byte;
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac, player.pid);