Bug in file.js

1 view
Skip to first unread message

ddoctor

unread,
Sep 28, 2010, 9:13:17 PM9/28/10
to Narwhal and Jack
Hi,

The following section of file.js in narwhal is causing open file leaks
for us. Basically, one of the files is not being closed:

exports.copy = function (source, target) {
source = exports.path(source);
target = exports.path(target);
source.open("rb").copy(target.open("wb")).close();
};

I think it should be something like this:

exports.copy = function (source, target) {
function open(mode, x) {
var p = exports.path(x);
p.open(mode);
return p;
}

var s = open(source, "rb");
var t = open(target, "wb");
s.copy(t);
s.close();
t.close();
};


Cheers,

ddoctor

Paul Baumgart

unread,
Sep 28, 2010, 10:34:11 PM9/28/10
to narw...@googlegroups.com
Do you have the latest version of Narwhal? This was fixed in August:
http://github.com/280north/narwhal/commit/8584ceaea9d4aa73cc9d1f45774698c26bdafe43

There's the potential for leaks if there's an error opening the files,
so I just sent a pull request for a better version that try/catches:
http://github.com/280north/narwhal/pull/16

Paul

> --
> You received this message because you are subscribed to the Google Groups "Narwhal and Jack" group.
> To post to this group, send email to narw...@googlegroups.com.
> To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/narwhaljs?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages