Fix potential crash

Even though the code is running on the main thread, it might still run after the owning (C++) object has been destroyed.
This commit is contained in:
Allan Odgaard
2013-02-05 23:32:16 +01:00
parent cafb518be8
commit fce82f0759

View File

@@ -51,9 +51,11 @@ struct item_record_t : fs::event_callback_t
if(_scm_info)
{
_scm_info->add_callback(^(scm::ng::info_t const& info){
_live.reset(new bool{true});
std::weak_ptr<bool> isAlive = _live;
if(!_item.children)
_scm_info->add_callback(^(scm::ng::info_t const& info){
if(!isAlive.lock() || !_item.children)
return;
std::set<std::string> pathsShown, pathsDeleted, pathsMissingOnDisk;
@@ -293,6 +295,7 @@ private:
std::string _path;
struct timespec _last_modified;
scm::ng::info_ptr _scm_info;
std::shared_ptr<bool> _live;
};
@implementation FSDirectoryDataSource