diff options
author | liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> | 2022-05-02 22:45:47 +0300 |
---|---|---|
committer | RafaelGSS <rafael.nunu@hotmail.com> | 2022-05-10 15:13:16 +0300 |
commit | cacff07e75afa6027dc3fe982209489b1b34ce68 (patch) | |
tree | 621f7db9b0b63562192fb9e7ef09029560d73f43 /test | |
parent | 1237c742f45090239e9d364b3309065132c71789 (diff) |
src: fix memory leak for v8.serialize
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.
Fixes: https://github.com/nodejs/node/issues/40828
Refs: https://github.com/nodejs/node/issues/38300
PR-URL: https://github.com/nodejs/node/pull/42695
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-v8-serialize-leak.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/parallel/test-v8-serialize-leak.js b/test/parallel/test-v8-serialize-leak.js new file mode 100644 index 00000000000..4e3a1d96f8a --- /dev/null +++ b/test/parallel/test-v8-serialize-leak.js @@ -0,0 +1,22 @@ +'use strict'; +// Flags: --expose-gc + +require('../common'); +const v8 = require('v8'); +const assert = require('assert'); + +const before = process.memoryUsage.rss(); + +for (let i = 0; i < 1000000; i++) { + v8.serialize(''); +} + +global.gc(); + +const after = process.memoryUsage.rss(); + +if (process.config.variables.asan) { + assert(after < before * 10, `asan: before=${before} after=${after}`); +} else { + assert(after < before * 2, `before=${before} after=${after}`); +} |