summaryrefslogtreecommitdiff
path: root/test/parallel/test-zlib-invalid-input-memory.js
blob: d626e6e5b8df380d2c87b083dda6208d927327ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Flags: --expose-gc
'use strict';
const common = require('../common');
const onGC = require('../common/ongc');
const assert = require('assert');
const zlib = require('zlib');

// Checks that, if a zlib context fails with an error, it can still be GC'ed:
// Refs: https://github.com/nodejs/node/issues/22705

const ongc = common.mustCall();

{
  const input = Buffer.from('foobar');
  const strm = zlib.createInflate();
  strm.end(input);
  strm.once('error', common.mustCall((err) => {
    assert(err);
    setImmediate(() => {
      global.gc();
      // Keep the event loop alive for seeing the async_hooks destroy hook
      // we use for GC tracking...
      // TODO(addaleax): This should maybe not be necessary?
      setImmediate(() => {});
    });
  }));
  onGC(strm, { ongc });
}