diff --git a/Source/Core/Common/LinearDiskCache.h b/Source/Core/Common/LinearDiskCache.h index 77feb0f473..4e9e136fa7 100644 --- a/Source/Core/Common/LinearDiskCache.h +++ b/Source/Core/Common/LinearDiskCache.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -72,7 +73,7 @@ public: // good header, read some key/value pairs K key; - V* value = nullptr; + std::unique_ptr value = nullptr; u32 value_size = 0; u32 entry_number = 0; @@ -82,14 +83,14 @@ public: if (next_extent > file_size) break; - delete[] value; - value = new V[value_size]; + // TODO: use make_unique_for_overwrite in C++20 + value = std::unique_ptr(new V[value_size]); // read key/value and pass to reader - if (m_file.ReadArray(&key, 1) && m_file.ReadArray(value, value_size) && + if (m_file.ReadArray(&key, 1) && m_file.ReadArray(value.get(), value_size) && m_file.ReadArray(&entry_number, 1) && entry_number == m_num_entries + 1) { - reader.Read(key, value, value_size); + reader.Read(key, value.get(), value_size); } else { @@ -100,7 +101,6 @@ public: } m_file.Clear(); - delete[] value; return m_num_entries; }