fix memory leak of char[] initialization

This commit is contained in:
Huyen Chau Nguyen 2016-10-19 11:55:35 -07:00
parent 316ef305de
commit 2d13116487
2 changed files with 5 additions and 4 deletions

View File

@ -149,9 +149,8 @@ class InternalDataFacade final : public BaseDataFacade
} }
auto timestamp_size = storage::io::readTimestampSize(timestamp_stream); auto timestamp_size = storage::io::readTimestampSize(timestamp_stream);
char *timestamp_ptr = new char[timestamp_size](); m_timestamp.resize(timestamp_size);
storage::io::readTimestamp(timestamp_stream, timestamp_ptr, timestamp_size); storage::io::readTimestamp(timestamp_stream, &m_timestamp.front(), timestamp_size);
m_timestamp = std::string(timestamp_ptr);
} }
void LoadGraph(const boost::filesystem::path &hsgr_path) void LoadGraph(const boost::filesystem::path &hsgr_path)

View File

@ -70,7 +70,9 @@ inline std::uint32_t readTimestampSize(boost::filesystem::ifstream &timestamp_in
} }
// Reads the timestamp in a file // Reads the timestamp in a file
inline void readTimestamp(boost::filesystem::ifstream &timestamp_input_stream, char *timestamp, std::size_t timestamp_length) inline void readTimestamp(boost::filesystem::ifstream &timestamp_input_stream,
char *timestamp,
std::size_t timestamp_length)
{ {
timestamp_input_stream.read(timestamp, timestamp_length * sizeof(char)); timestamp_input_stream.read(timestamp, timestamp_length * sizeof(char));
} }