From 2d13116487dff16b58805b23cbc8a5e64f2b4022 Mon Sep 17 00:00:00 2001 From: Huyen Chau Nguyen Date: Wed, 19 Oct 2016 11:55:35 -0700 Subject: [PATCH] fix memory leak of char[] initialization --- include/engine/datafacade/internal_datafacade.hpp | 5 ++--- include/storage/io.hpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index c5fc17cde..9d3b12f9e 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -149,9 +149,8 @@ class InternalDataFacade final : public BaseDataFacade } auto timestamp_size = storage::io::readTimestampSize(timestamp_stream); - char *timestamp_ptr = new char[timestamp_size](); - storage::io::readTimestamp(timestamp_stream, timestamp_ptr, timestamp_size); - m_timestamp = std::string(timestamp_ptr); + m_timestamp.resize(timestamp_size); + storage::io::readTimestamp(timestamp_stream, &m_timestamp.front(), timestamp_size); } void LoadGraph(const boost::filesystem::path &hsgr_path) diff --git a/include/storage/io.hpp b/include/storage/io.hpp index 02907f8b8..644e9a4bb 100644 --- a/include/storage/io.hpp +++ b/include/storage/io.hpp @@ -70,7 +70,9 @@ inline std::uint32_t readTimestampSize(boost::filesystem::ifstream ×tamp_in } // Reads the timestamp in a file -inline void readTimestamp(boost::filesystem::ifstream ×tamp_input_stream, char *timestamp, std::size_t timestamp_length) +inline void readTimestamp(boost::filesystem::ifstream ×tamp_input_stream, + char *timestamp, + std::size_t timestamp_length) { timestamp_input_stream.read(timestamp, timestamp_length * sizeof(char)); }