[flang] fix double deallocation bug from previous commit

Original-commit: flang-compiler/f18@f216b6bb82
Reviewed-on: https://github.com/flang-compiler/f18/pull/151
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-07-27 13:10:01 -07:00
parent 544f9d5e74
commit fa30061f09
2 changed files with 6 additions and 4 deletions

View File

@ -204,9 +204,9 @@ bool SourceFile::ReadFile(std::string errorPath, std::stringstream *error) {
// empty file
content_ = nullptr;
} else {
buffer_ = buffer.MarshalNormalized(); // no '\r' chars, ensure final '\n'
content_ = buffer_.data();
bytes_ = buffer_.size();
normalized_ = buffer.MarshalNormalized();
content_ = normalized_.data();
bytes_ = normalized_.size();
lineStart_ = FindLineStarts(content_, bytes_);
}
return true;
@ -216,6 +216,8 @@ void SourceFile::Close() {
if (useMMap && isMemoryMapped_) {
munmap(reinterpret_cast<void *>(const_cast<char *>(content_)), bytes_);
isMemoryMapped_ = false;
} else if (!normalized_.empty()) {
normalized_.clear();
} else if (content_ != nullptr) {
delete[] content_;
}

View File

@ -57,7 +57,7 @@ private:
const char *content_{nullptr};
std::size_t bytes_{0};
std::vector<std::size_t> lineStart_;
std::string buffer_;
std::string normalized_;
};
} // namespace Fortran::parser