From 04fa6d675f4646d36aa9843cb0de5ffa834a14c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Tue, 30 Jul 2019 07:45:31 +0100 Subject: [PATCH] fs: close file descriptor of promisified truncate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original PR: PR-URL: https://github.com/nodejs/node/pull/28858 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig PR-URL: https://github.com/nodejs/node/pull/34239 Reviewed-By: Anna Henningsen Reviewed-By: Richard Lau Reviewed-By: Gerhard Stöbich --- lib/internal/fs/promises.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index d653724474f314..31eaeef2846216 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -305,7 +305,8 @@ async function rename(oldPath, newPath) { } async function truncate(path, len = 0) { - return ftruncate(await open(path, 'r+'), len); + const fd = await open(path, 'r+'); + return ftruncate(fd, len).finally(fd.close.bind(fd)); } async function ftruncate(handle, len = 0) {