DumpHeapSnapShot memory leak bugfix

desc: DumpHeapSnapShot memory leak bugfix

solu:
1. StreamWriter need release in deconstructing;
2. not if good, should be if is_open can close fileStream;

issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I7LE8L
Signed-off-by: wanghuan2022 <wanghuan80@huawei.com>
Change-Id: I9c4cc04870b97b118e02e974eff513518961abae
This commit is contained in:
wanghuan2022 2023-07-15 17:20:21 +08:00
parent dce64226bc
commit dd213a33e0
3 changed files with 9 additions and 4 deletions

View File

@ -32,9 +32,14 @@ FileStream::FileStream(const std::string &fileName)
Initialize(fileName);
}
FileStream::~FileStream()
{
EndOfStream();
}
void FileStream::EndOfStream()
{
if (Good()) {
if (fileStream_.is_open()) {
fileStream_.close();
}
}
@ -50,7 +55,6 @@ void FileStream::Initialize(const std::string &fileName)
std::pair<bool, std::string> realPath = FilePathValid(fileName);
if (!realPath.first) {
LOG_ECMA(ERROR) << "FileStream: check file path failed";
fileStream_.close();
return;
}

View File

@ -28,7 +28,7 @@ namespace panda::ecmascript {
class FileStream : public Stream {
public:
explicit FileStream(const std::string &fileName);
~FileStream() override = default;
~FileStream() override;
void EndOfStream() override;

View File

@ -22,8 +22,9 @@ namespace panda::ecmascript {
HeapSnapshotJSONSerializer::~HeapSnapshotJSONSerializer()
{
if (!writer_) {
if (writer_) {
delete writer_;
writer_ = nullptr;
}
}