protocol: Fix memory leak in Packet when data isn't read succesfully

This commit is contained in:
Joshua Scott 2018-04-06 04:52:58 +01:00
parent f2247f03f4
commit a13731ccc0
1 changed files with 10 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include "../util/Serializable.h"
#include "exception.h"
#include <cstdint>
#include <vector>
#include <sstream>
@ -41,7 +42,15 @@ namespace protocol
std::istringstream iss(std::string(m_payload.data(), m_payload.size()));
DataT *data = new DataT();
try
{
data->read_from(iss);
}
catch (parse_error &e)
{
delete data;
throw;
}
return data;
}