Fix safe-pathwatcher memory leak

This commit is contained in:
David Glasser
2014-12-17 00:05:50 -08:00
parent 6a55c35837
commit bd54f09e4c

View File

@@ -64,7 +64,10 @@ exports.testDirectory = function (dir) {
try {
// Watch the candidate directory using pathwatcher.watch.
var watcher = files.pathwatcherWatch(dir, cleanUp);
var watcher = files.pathwatcherWatch(dir, function () {
cleanUp();
switchFunctions = null;
});
} catch (err) {
// If the directory did not exist, do not treat this failure as
@@ -110,17 +113,19 @@ exports.watch = function (absPath, callback) {
var closed = false;
var switched = false;
switchFunctions.push(function switchToPolling() {
if (! switched && ! closed) {
switched = true;
watcher.close();
if (switchFunctions) {
switchFunctions.push(function switchToPolling() {
if (! switched && ! closed) {
switched = true;
watcher.close();
// Re-watch the file using files.watchFile instead.
files.watchFile(absPath, {
interval: pollingInterval
}, callback);
}
});
// Re-watch the file using files.watchFile instead.
files.watchFile(absPath, {
interval: pollingInterval
}, callback);
}
});
}
return {
close: function close() {