mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-23 15:22:45 +01:00
romfs: Remove cyclic shared_ptr leak in romfs code
This commit is contained in:
parent
893447b6b0
commit
149bda980a
3 changed files with 8 additions and 8 deletions
|
@ -65,7 +65,7 @@ void ProcessFile(VirtualFile file, size_t file_offset, size_t data_offset, u32 t
|
||||||
auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset);
|
auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset);
|
||||||
|
|
||||||
parent->AddFile(std::make_shared<OffsetVfsFile>(
|
parent->AddFile(std::make_shared<OffsetVfsFile>(
|
||||||
file, entry.first.size, entry.first.offset + data_offset, entry.second, parent));
|
file, entry.first.size, entry.first.offset + data_offset, entry.second));
|
||||||
|
|
||||||
if (entry.first.sibling == ROMFS_ENTRY_EMPTY)
|
if (entry.first.sibling == ROMFS_ENTRY_EMPTY)
|
||||||
break;
|
break;
|
||||||
|
@ -79,7 +79,7 @@ void ProcessDirectory(VirtualFile file, size_t dir_offset, size_t file_offset, s
|
||||||
while (true) {
|
while (true) {
|
||||||
auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset);
|
auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset);
|
||||||
auto current = std::make_shared<VectorVfsDirectory>(
|
auto current = std::make_shared<VectorVfsDirectory>(
|
||||||
std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, parent, entry.second);
|
std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, entry.second);
|
||||||
|
|
||||||
if (entry.first.child_file != ROMFS_ENTRY_EMPTY) {
|
if (entry.first.child_file != ROMFS_ENTRY_EMPTY) {
|
||||||
ProcessFile(file, file_offset, data_offset, entry.first.child_file, current);
|
ProcessFile(file, file_offset, data_offset, entry.first.child_file, current);
|
||||||
|
@ -108,9 +108,9 @@ VirtualDir ExtractRomFS(VirtualFile file) {
|
||||||
const u64 file_offset = header.file_meta.offset;
|
const u64 file_offset = header.file_meta.offset;
|
||||||
const u64 dir_offset = header.directory_meta.offset + 4;
|
const u64 dir_offset = header.directory_meta.offset + 4;
|
||||||
|
|
||||||
const auto root =
|
auto root =
|
||||||
std::make_shared<VectorVfsDirectory>(std::vector<VirtualFile>{}, std::vector<VirtualDir>{},
|
std::make_shared<VectorVfsDirectory>(std::vector<VirtualFile>{}, std::vector<VirtualDir>{},
|
||||||
file->GetContainingDirectory(), file->GetName());
|
file->GetName(), file->GetContainingDirectory());
|
||||||
|
|
||||||
ProcessDirectory(file, dir_offset, file_offset, header.data_offset, 0, root);
|
ProcessDirectory(file, dir_offset, file_offset, header.data_offset, 0, root);
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_,
|
VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_,
|
||||||
std::vector<VirtualDir> dirs_, VirtualDir parent_,
|
std::vector<VirtualDir> dirs_, std::string name_,
|
||||||
std::string name_)
|
VirtualDir parent_)
|
||||||
: files(std::move(files_)), dirs(std::move(dirs_)), parent(std::move(parent_)),
|
: files(std::move(files_)), dirs(std::move(dirs_)), parent(std::move(parent_)),
|
||||||
name(std::move(name_)) {}
|
name(std::move(name_)) {}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ namespace FileSys {
|
||||||
// Vector data is supplied upon construction.
|
// Vector data is supplied upon construction.
|
||||||
struct VectorVfsDirectory : public VfsDirectory {
|
struct VectorVfsDirectory : public VfsDirectory {
|
||||||
explicit VectorVfsDirectory(std::vector<VirtualFile> files = {},
|
explicit VectorVfsDirectory(std::vector<VirtualFile> files = {},
|
||||||
std::vector<VirtualDir> dirs = {}, VirtualDir parent = nullptr,
|
std::vector<VirtualDir> dirs = {}, std::string name = "",
|
||||||
std::string name = "");
|
VirtualDir parent = nullptr);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
|
std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
|
||||||
std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
|
std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
|
||||||
|
|
Loading…
Reference in a new issue