From 4b1f95c6c9ddf717731cdf7a54c85e9a0129daf6 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Mon, 18 Aug 2014 11:15:48 -0400 Subject: [PATCH 1/2] Fix descriptor leaks in writeFile and appendFile --- src/filesystem/implementation.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index e050076..613aae1 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1785,11 +1785,13 @@ function writeFile(fs, context, path, data, options, callback) { var ofd = new OpenFileDescription(path, fileNode.id, flags, 0); var fd = fs.allocDescriptor(ofd); - replace_data(context, ofd, data, 0, data.length, function(err2, nbytes) { - if(err2) { - return callback(err2); - } + replace_data(context, ofd, data, 0, data.length, function(err, nbytes) { fs.releaseDescriptor(fd); + ofd = null; + + if(err) { + return callback(err); + } callback(null); }); }); @@ -1821,11 +1823,13 @@ function appendFile(fs, context, path, data, options, callback) { var ofd = new OpenFileDescription(path, fileNode.id, flags, fileNode.size); var fd = fs.allocDescriptor(ofd); - write_data(context, ofd, data, 0, data.length, ofd.position, function(err2, nbytes) { - if(err2) { - return callback(err2); - } + write_data(context, ofd, data, 0, data.length, ofd.position, function(err, nbytes) { fs.releaseDescriptor(fd); + ofd = null; + + if(err) { + return callback(err); + } callback(null); }); }); From ed0137deceff1686c7a27702625b85f7fe8e634d Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Mon, 18 Aug 2014 11:23:24 -0400 Subject: [PATCH 2/2] Remove redundant code per review --- src/filesystem/implementation.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 613aae1..7b406ce 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1703,7 +1703,6 @@ function readFile(fs, context, path, options, callback) { function cleanup() { fs.releaseDescriptor(fd); - ofd = null; } fstat_file(context, ofd, function(err, fstatResult) { @@ -1787,7 +1786,6 @@ function writeFile(fs, context, path, data, options, callback) { replace_data(context, ofd, data, 0, data.length, function(err, nbytes) { fs.releaseDescriptor(fd); - ofd = null; if(err) { return callback(err); @@ -1825,7 +1823,6 @@ function appendFile(fs, context, path, data, options, callback) { write_data(context, ofd, data, 0, data.length, ofd.position, function(err, nbytes) { fs.releaseDescriptor(fd); - ofd = null; if(err) { return callback(err);