mirror of
https://gitee.com/openharmony/arkcompiler_runtime_core
synced 2024-11-24 07:10:22 +00:00
Fix potential handle leak
Fix potential handle leak Issue: #I6AUHK Signed-off-by: qiuyu <qiuyu22@huawei.com> Change-Id: Ic2d17aa1414b1d2307f97d704a74d3fcf05b95c7
This commit is contained in:
parent
b30ad02ceb
commit
ed203b793f
@ -219,6 +219,7 @@ std::unique_ptr<const panda_file::File> OpenPandaFile(std::string_view location,
|
||||
auto open_error = OpenArchiveFile(zipfile, fp);
|
||||
if (open_error != ZIPARCHIVE_OK) {
|
||||
LOG(ERROR, PANDAFILE) << "Can't open archive " << location;
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
bool try_default = archive_filename.empty();
|
||||
@ -242,6 +243,7 @@ std::unique_ptr<const panda_file::File> OpenPandaFile(std::string_view location,
|
||||
if (GetCurrentFileInfo(zipfile, &entry) != ZIPARCHIVE_OK) {
|
||||
OpenPandaFileFromZipErrorHandler(zipfile);
|
||||
LOG(ERROR, PANDAFILE) << "GetCurrentFileInfo error";
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
// check that file is not empty, otherwise crash at CloseArchiveFile
|
||||
@ -249,12 +251,14 @@ std::unique_ptr<const panda_file::File> OpenPandaFile(std::string_view location,
|
||||
OpenPandaFileFromZipErrorHandler(zipfile);
|
||||
LOG(ERROR, PANDAFILE) << "Invalid panda file '" << (try_default ? ARCHIVE_FILENAME : archive_filename)
|
||||
<< "'";
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
if (OpenCurrentFile(zipfile) != ZIPARCHIVE_OK) {
|
||||
CloseCurrentFile(zipfile);
|
||||
OpenPandaFileFromZipErrorHandler(zipfile);
|
||||
LOG(ERROR, PANDAFILE) << "Can't OpenCurrentFile!";
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
GetCurrentFileOffset(zipfile, &entry);
|
||||
@ -262,6 +266,7 @@ std::unique_ptr<const panda_file::File> OpenPandaFile(std::string_view location,
|
||||
CloseCurrentFile(zipfile);
|
||||
if (panda::CloseArchiveFile(zipfile) != 0) {
|
||||
LOG(ERROR, PANDAFILE) << "CloseArchive failed!";
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
|
@ -295,6 +295,7 @@ HWTEST(File, CheckHeader, testing::ext::TestSize.Level0)
|
||||
os::mem::MMAP_FLAG_PRIVATE, writer.GetOffset()).ToConst();
|
||||
EXPECT_NE(ptr.Get(), nullptr);
|
||||
EXPECT_TRUE(CheckHeader(ptr, ABC_FILE));
|
||||
fclose(fp);
|
||||
|
||||
remove(ABC_FILE);
|
||||
}
|
||||
|
@ -230,6 +230,7 @@ static void UnzipFileCheckTxt(const char *archivename, char *filename, const cha
|
||||
os::mem::UnmapRaw(mem, size_to_mmap);
|
||||
CloseCurrentFile(zipfile);
|
||||
CloseArchive(zipfile);
|
||||
fclose(myfile);
|
||||
ASSERT_EQ(1, 0) << "ExtractToMemory() failed!, uncompressed_length is " << uncompressed_length - 1
|
||||
<< ", original strlen is " << dlen;
|
||||
return;
|
||||
@ -239,6 +240,7 @@ static void UnzipFileCheckTxt(const char *archivename, char *filename, const cha
|
||||
os::mem::UnmapRaw(mem, size_to_mmap);
|
||||
CloseCurrentFile(zipfile);
|
||||
CloseArchive(zipfile);
|
||||
fclose(myfile);
|
||||
ASSERT_EQ(1, 0) << "ExtractToMemory() memcmp failed!";
|
||||
return;
|
||||
}
|
||||
@ -460,6 +462,7 @@ static void UnzipFileCheckInDirectory(const char *archivename, char *filename, c
|
||||
os::mem::UnmapRaw(mem, size_to_mmap);
|
||||
CloseCurrentFile(zipfile);
|
||||
CloseArchive(zipfile);
|
||||
fclose(myfile);
|
||||
ASSERT_EQ(1, 0) << "ExtractToMemory() failed!, uncompressed_length is " << uncompressed_length - 1
|
||||
<< ", original strlen is " << dlen;
|
||||
return;
|
||||
@ -469,6 +472,7 @@ static void UnzipFileCheckInDirectory(const char *archivename, char *filename, c
|
||||
os::mem::UnmapRaw(mem, size_to_mmap);
|
||||
CloseCurrentFile(zipfile);
|
||||
CloseArchive(zipfile);
|
||||
fclose(myfile);
|
||||
ASSERT_EQ(1, 0) << "ExtractToMemory() memcmp failed!";
|
||||
return;
|
||||
}
|
||||
|
@ -55,16 +55,19 @@ void OpenUncompressedArchiveFuzzTest(const uint8_t *data, size_t size)
|
||||
}
|
||||
if (panda::LocateFile(zipfile, filename) != panda::ZIPARCHIVE_OK) {
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
(void)fclose(fp);
|
||||
return;
|
||||
}
|
||||
panda::EntryFileStat entry;
|
||||
if (panda::GetCurrentFileInfo(zipfile, &entry) != panda::ZIPARCHIVE_OK) {
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
(void)fclose(fp);
|
||||
return;
|
||||
}
|
||||
if (panda::OpenCurrentFile(zipfile) != panda::ZIPARCHIVE_OK) {
|
||||
panda::CloseCurrentFile(zipfile);
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
(void)fclose(fp);
|
||||
return;
|
||||
}
|
||||
panda::GetCurrentFileOffset(zipfile, &entry);
|
||||
|
Loading…
Reference in New Issue
Block a user