From 1300d6178e8863a220fa301e9fde8be3580d9b66 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 17 Mar 2023 02:55:12 +0530 Subject: fix(ext/node): resource leak in createHmac (#18229) This commit fixes https://github.com/denoland/deno/issues/18140. Verified that test fails on `main`. --- ext/node/polyfills/internal/crypto/hash.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/node/polyfills/internal/crypto') diff --git a/ext/node/polyfills/internal/crypto/hash.ts b/ext/node/polyfills/internal/crypto/hash.ts index de7b16297..d81844f30 100644 --- a/ext/node/polyfills/internal/crypto/hash.ts +++ b/ext/node/polyfills/internal/crypto/hash.ts @@ -178,7 +178,6 @@ class HmacImpl extends Transform { const u8Key = prepareSecretKey(key, options?.encoding) as Buffer; const alg = hmac.toLowerCase(); - this.#hash = new Hash(alg, options); this.#algorithm = alg; const blockSize = (alg === "sha512" || alg === "sha384") ? 128 : 64; const keySize = u8Key.length; @@ -186,7 +185,8 @@ class HmacImpl extends Transform { let bufKey: Buffer; if (keySize > blockSize) { - bufKey = this.#hash.update(u8Key).digest() as Buffer; + const hash = new Hash(alg, options); + bufKey = hash.update(u8Key).digest() as Buffer; } else { bufKey = Buffer.concat([u8Key, this.#ZEROES], blockSize); } -- cgit v1.2.3