Skip to content

Commit 2db387a

Browse files
committed
Use Stream.destroy() to ensure stream is closed before unlinking upon failure, this prevents a memory leak and on Windows a failure to delete the file.
Even though this is not an officially documented function until Node v8 it works all the way down to v0.12.
1 parent fd85869 commit 2db387a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ function ConManager(baseurl, token_name) {
400400
let f = fs.createWriteStream(file, 'binary').on('error', reject);
401401

402402
this.downloadStream(cmpath).on('error', (e) => {
403-
fs.unlinkSync(file);
404-
reject(e);
403+
f.destroy(e);
405404
}).pipe(f).on('close', resolve).on('error', (e) => {
405+
f.destroy();
406406
fs.unlinkSync(file);
407407
reject(e);
408408
});

0 commit comments

Comments
 (0)