mirror of https://github.com/lukechilds/node.git
Browse Source
Fix a memory leak in dh.setPublicKey() and dh.setPrivateKey() where the old keys weren't freed. Fixes: https://github.com/nodejs/node/issues/8377 PR-URL: https://github.com/nodejs/node/pull/14122 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>v6
Ben Noordhuis
8 years ago
3 changed files with 53 additions and 29 deletions
@ -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); |
Loading…
Reference in new issue