Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib: fix memory leak for unused zlib instances #21607

Merged
merged 1 commit into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
refs_(0),
gzip_id_bytes_read_(0),
write_result_(nullptr) {
MakeWeak();
}


Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-zlib-unused-weak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
// Flags: --expose-gc
require('../common');
const assert = require('assert');
const zlib = require('zlib');

// Tests that native zlib handles start out their life as weak handles.

const before = process.memoryUsage().external;
for (let i = 0; i < 100; ++i)
zlib.createGzip();
const afterCreation = process.memoryUsage().external;
global.gc();
const afterGC = process.memoryUsage().external;

assert((afterGC - before) / (afterCreation - before) <= 0.05,
`Expected after-GC delta ${afterGC - before} to be less than 5 %` +
` of before-GC delta ${afterCreation - before}`);