-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zlib: fix memory leak for unused zlib instances
An oversight in an earlier commit led to a memory leak in the untypical situation that zlib instances are created but never used, because zlib handles no longer started out their life as weak handles. The bug was introduced in bd20110. Refs: #20455 PR-URL: #21607 Reviewed-By: Tobias Nießen <[email protected]>
- Loading branch information
Showing
2 changed files
with
19 additions
and
0 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
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}`); |