Make refcounting actually work in wxFileSystemWatcher::Add()
The order of refcounting operations should be the opposite of what it
was: first check if the path is not watched already and only if it is
not call m_service->Add() to actually watch it. (Previously reference
count was kept track of, but m_service->Add() was always called, i.e.
the calls were repeated and unbalanced with Remove() calls.)
Remove() already has the correct order and only calls
m_service->Remove() when the path's refcount reaches zero.
This fixes a problem which was there since the original code was added
back in 76cfd1bf95
(Make wxFileSystemWatcher watch entries
reference-counted., 2012-10-15).
Closes https://github.com/wxWidgets/wxWidgets/pull/2203
This commit is contained in:
committed by
Vadim Zeitlin
parent
c65d5110aa
commit
8e80941183
@@ -121,17 +121,15 @@ wxFileSystemWatcherBase::AddAny(const wxFileName& path,
|
||||
if (canonical.IsEmpty())
|
||||
return false;
|
||||
|
||||
// adding a path in a platform specific way
|
||||
wxFSWatchInfo watch(canonical, events, type, filespec);
|
||||
if ( !m_service->Add(watch) )
|
||||
return false;
|
||||
|
||||
// on success, either add path to our 'watch-list'
|
||||
// or, if already watched, inc the refcount. This may happen if
|
||||
// a dir is Add()ed, then later AddTree() is called on a parent dir
|
||||
// Check if the patch isn't already being watched.
|
||||
wxFSWatchInfoMap::iterator it = m_watches.find(canonical);
|
||||
if ( it == m_watches.end() )
|
||||
{
|
||||
// It isn't, so start watching it in a platform specific way:
|
||||
wxFSWatchInfo watch(canonical, events, type, filespec);
|
||||
if ( !m_service->Add(watch) )
|
||||
return false;
|
||||
|
||||
wxFSWatchInfoMap::value_type val(canonical, watch);
|
||||
m_watches.insert(val);
|
||||
}
|
||||
|
Reference in New Issue
Block a user