use unique_ptr
MODIFY
util/file.cpp
util/file.cpp
@@ -20,13 +20,9 @@ file_reader::file_reader(const char *filename, unsigned padding) {
f.seekg(0, ios::end);
sz = f.tellg();
f.seekg(0, ios::beg);
- buf = new char[sz + padding];
- f.read(buf, sz);
- memset(buf + sz, 0, padding);
-}
-
-file_reader::~file_reader() {
- delete[] buf;
+ buf = make_unique<char[]>(sz + padding);
+ f.read(buf.get(), sz);
+ memset(buf.get() + sz, 0, padding);
}

MODIFY
util/file.h
util/file.h
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
+#include <memory>
#include <string>
#include <string_view>
namespace util {
class file_reader {
- char *buf = nullptr;
+ std::unique_ptr<char[]> buf;
size_t sz;
public:
file_reader(const char *filename, unsigned padding = 0);
- ~file_reader();
std::string_view operator*() const {
- return { buf, sz };
+ return { buf.get(), sz };
}
};

use unique_ptr