From c60472d66ae0c3475ff4d1c783a8d3ac0d22ba1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=BF=AF?= Date: Mon, 6 Mar 2023 10:50:27 +0800 Subject: [PATCH] fix invalid watcher iterator while found before removing it from map collection --- src/efsw/FileWatcherInotify.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/efsw/FileWatcherInotify.cpp b/src/efsw/FileWatcherInotify.cpp index 2305891..b82a49d 100644 --- a/src/efsw/FileWatcherInotify.cpp +++ b/src/efsw/FileWatcherInotify.cpp @@ -341,12 +341,9 @@ void FileWatcherInotify::run() { struct inotify_event* pevent = (struct inotify_event*)&buff[i]; { - { - Lock lock( mWatchesLock ); - - wit = mWatches.find( pevent->wd ); - } + Lock lock( mWatchesLock ); + wit = mWatches.find( pevent->wd ); if ( wit != mWatches.end() ) { handleAction( wit->second, (char*)pevent->name, pevent->mask ); @@ -383,6 +380,7 @@ void FileWatcherInotify::run() { prevOldFileName = std::string( (char*)pevent->name ); } + i += sizeof( struct inotify_event ) + pevent->len; } }