forked from OSchip/llvm-project
[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:
parent
544f9d5e74
commit
fa30061f09
|
@ -204,9 +204,9 @@ bool SourceFile::ReadFile(std::string errorPath, std::stringstream *error) {
|
||||||
// empty file
|
// empty file
|
||||||
content_ = nullptr;
|
content_ = nullptr;
|
||||||
} else {
|
} else {
|
||||||
buffer_ = buffer.MarshalNormalized(); // no '\r' chars, ensure final '\n'
|
normalized_ = buffer.MarshalNormalized();
|
||||||
content_ = buffer_.data();
|
content_ = normalized_.data();
|
||||||
bytes_ = buffer_.size();
|
bytes_ = normalized_.size();
|
||||||
lineStart_ = FindLineStarts(content_, bytes_);
|
lineStart_ = FindLineStarts(content_, bytes_);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -216,6 +216,8 @@ void SourceFile::Close() {
|
||||||
if (useMMap && isMemoryMapped_) {
|
if (useMMap && isMemoryMapped_) {
|
||||||
munmap(reinterpret_cast<void *>(const_cast<char *>(content_)), bytes_);
|
munmap(reinterpret_cast<void *>(const_cast<char *>(content_)), bytes_);
|
||||||
isMemoryMapped_ = false;
|
isMemoryMapped_ = false;
|
||||||
|
} else if (!normalized_.empty()) {
|
||||||
|
normalized_.clear();
|
||||||
} else if (content_ != nullptr) {
|
} else if (content_ != nullptr) {
|
||||||
delete[] content_;
|
delete[] content_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ private:
|
||||||
const char *content_{nullptr};
|
const char *content_{nullptr};
|
||||||
std::size_t bytes_{0};
|
std::size_t bytes_{0};
|
||||||
std::vector<std::size_t> lineStart_;
|
std::vector<std::size_t> lineStart_;
|
||||||
std::string buffer_;
|
std::string normalized_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Fortran::parser
|
} // namespace Fortran::parser
|
||||||
|
|
Loading…
Reference in New Issue