mirror of https://github.com/SeanOMik/libki.git
protocol: Fix memory leak in Packet when data isn't read succesfully
This commit is contained in:
parent
f2247f03f4
commit
a13731ccc0
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../util/Serializable.h"
|
#include "../util/Serializable.h"
|
||||||
|
#include "exception.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -41,7 +42,15 @@ namespace protocol
|
||||||
|
|
||||||
std::istringstream iss(std::string(m_payload.data(), m_payload.size()));
|
std::istringstream iss(std::string(m_payload.data(), m_payload.size()));
|
||||||
DataT *data = new DataT();
|
DataT *data = new DataT();
|
||||||
|
try
|
||||||
|
{
|
||||||
data->read_from(iss);
|
data->read_from(iss);
|
||||||
|
}
|
||||||
|
catch (parse_error &e)
|
||||||
|
{
|
||||||
|
delete data;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue