-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix memory leak in DH key setters
Fix a memory leak in dh.setPublicKey() and dh.setPrivateKey() where the old keys weren't freed. Fixes: #8377 PR-URL: #14122 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
0bbdb78
commit f237ad5
Showing
3 changed files
with
53 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const crypto = require('crypto'); | ||
|
||
const before = process.memoryUsage().rss; | ||
{ | ||
const dh = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256); | ||
const publicKey = dh.generateKeys(); | ||
const privateKey = dh.getPrivateKey(); | ||
for (let i = 0; i < 5e4; i += 1) { | ||
dh.setPublicKey(publicKey); | ||
dh.setPrivateKey(privateKey); | ||
} | ||
} | ||
global.gc(); | ||
const after = process.memoryUsage().rss; | ||
|
||
// RSS should stay the same, ceteris paribus, but allow for | ||
// some slop because V8 mallocs memory during execution. | ||
assert(after - before < 5 << 20); |