Merge pull request #257 from humphd/fix-ofd-leaks
Fix descriptor leaks in writeFile and appendFile
This commit is contained in:
commit
a467711c90
|
@ -1703,7 +1703,6 @@ function readFile(fs, context, path, options, callback) {
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
fs.releaseDescriptor(fd);
|
fs.releaseDescriptor(fd);
|
||||||
ofd = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fstat_file(context, ofd, function(err, fstatResult) {
|
fstat_file(context, ofd, function(err, fstatResult) {
|
||||||
|
@ -1785,11 +1784,12 @@ function writeFile(fs, context, path, data, options, callback) {
|
||||||
var ofd = new OpenFileDescription(path, fileNode.id, flags, 0);
|
var ofd = new OpenFileDescription(path, fileNode.id, flags, 0);
|
||||||
var fd = fs.allocDescriptor(ofd);
|
var fd = fs.allocDescriptor(ofd);
|
||||||
|
|
||||||
replace_data(context, ofd, data, 0, data.length, function(err2, nbytes) {
|
replace_data(context, ofd, data, 0, data.length, function(err, nbytes) {
|
||||||
if(err2) {
|
|
||||||
return callback(err2);
|
|
||||||
}
|
|
||||||
fs.releaseDescriptor(fd);
|
fs.releaseDescriptor(fd);
|
||||||
|
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
callback(null);
|
callback(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1821,11 +1821,12 @@ function appendFile(fs, context, path, data, options, callback) {
|
||||||
var ofd = new OpenFileDescription(path, fileNode.id, flags, fileNode.size);
|
var ofd = new OpenFileDescription(path, fileNode.id, flags, fileNode.size);
|
||||||
var fd = fs.allocDescriptor(ofd);
|
var fd = fs.allocDescriptor(ofd);
|
||||||
|
|
||||||
write_data(context, ofd, data, 0, data.length, ofd.position, function(err2, nbytes) {
|
write_data(context, ofd, data, 0, data.length, ofd.position, function(err, nbytes) {
|
||||||
if(err2) {
|
|
||||||
return callback(err2);
|
|
||||||
}
|
|
||||||
fs.releaseDescriptor(fd);
|
fs.releaseDescriptor(fd);
|
||||||
|
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
callback(null);
|
callback(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue