diff --git a/src/app/file_system.cpp b/src/app/file_system.cpp index 41905592f..13910099e 100644 --- a/src/app/file_system.cpp +++ b/src/app/file_system.cpp @@ -961,7 +961,7 @@ static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_ return nullptr; // new file-item - FileItem* fileitem = new FileItem(nullptr); + auto fileitem = std::make_unique(nullptr); fileitem->m_fullpidl = clone_pidl(fullpidl); { @@ -974,25 +974,25 @@ static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_ free_pidl(parent_fullpidl); // The parent folder is sometimes deleted for some reasons. In - // that case, m_parent becomes nullptr, which can causes crash. - if (fileitem->m_parent == nullptr) { - throw std::runtime_error( - "Unexpected file system change. Please check the file."); - } + // that case, m_parent becomes nullptr, so we cannot use it + // anymore. Here we just return nullptr to indicate that the item + // doesn't exist anymore. + if (fileitem->m_parent == nullptr) + return nullptr; // Get specific pidl attributes if (fileitem->m_pidl && fileitem->m_parent) { - attrib = get_pidl_attrib(fileitem, attrib); + attrib = get_pidl_attrib(fileitem.get(), attrib); } } - update_by_pidl(fileitem, attrib); - put_fileitem(fileitem); + update_by_pidl(fileitem.get(), attrib); + put_fileitem(fileitem.get()); //LOG("FS: fileitem %p created %s with parent %p\n", fileitem, fileitem->keyname.c_str(), fileitem->parent); - return fileitem; + return fileitem.release(); } // Inserts the fileitem in the hash map of items.