mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 20:17:13 +02:00
FileManager+LibGUI: Fix two folder-related crashes (#569)
Fix a crash when opening a folder, and another one when trying to open a newly created folder. It was not safe to modify a GModelSelection while it's being iterated over. Fixes #536.
This commit is contained in:
committed by
Andreas Kling
parent
caf1b37e75
commit
a4d52b122d
Notes:
sideshowbarker
2024-07-19 12:04:50 +09:00
Author: https://github.com/xeons Commit: https://github.com/SerenityOS/serenity/commit/a4d52b122d9 Pull-request: https://github.com/SerenityOS/serenity/pull/569 Reviewed-by: https://github.com/awesomekling
@@ -31,6 +31,15 @@ struct GFileSystemModel::Node {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
for (auto& child: children) {
|
||||
child->cleanup();
|
||||
delete child;
|
||||
}
|
||||
children.clear();
|
||||
}
|
||||
|
||||
void traverse_if_needed(const GFileSystemModel& model)
|
||||
{
|
||||
if (type != Node::Directory || has_traversed)
|
||||
@@ -146,15 +155,22 @@ GFileSystemModel::~GFileSystemModel()
|
||||
|
||||
void GFileSystemModel::update()
|
||||
{
|
||||
// FIXME: Support refreshing the model!
|
||||
if (m_root)
|
||||
return;
|
||||
cleanup();
|
||||
|
||||
m_root = new Node;
|
||||
m_root->name = m_root_path;
|
||||
m_root->reify_if_needed(*this);
|
||||
}
|
||||
|
||||
void GFileSystemModel::cleanup()
|
||||
{
|
||||
if (m_root) {
|
||||
m_root->cleanup();
|
||||
delete m_root;
|
||||
m_root = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int GFileSystemModel::row_count(const GModelIndex& index) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
|
||||
Reference in New Issue
Block a user