From 4b6e9aa6aa2256da1ec7ed08f819cbf5d1463741 Mon Sep 17 00:00:00 2001 From: Sergey Aleynikov Date: Thu, 5 Jan 2017 01:33:32 +0300 Subject: [PATCH] Fix memory leak in B::RHE->HASH method. --- ext/B/B.pm | 2 +- ext/B/B.xs | 2 +- t/op/svleak.t | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ext/B/B.pm b/ext/B/B.pm index 9e58700..ff56fe7 100644 --- a/ext/B/B.pm +++ b/ext/B/B.pm @@ -15,7 +15,7 @@ require Exporter; # walkoptree comes from B.xs BEGIN { - $B::VERSION = '1.66'; + $B::VERSION = '1.67'; @B::EXPORT_OK = (); # Our BOOT code needs $VERSION set, and will append to @EXPORT_OK. diff --git a/ext/B/B.xs b/ext/B/B.xs index 5143305..310f50d 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -2064,7 +2064,7 @@ SV* HASH(h) B::RHE h CODE: - RETVAL = newRV( (SV*)cophh_2hv(h, 0) ); + RETVAL = newRV_noinc( (SV*)cophh_2hv(h, 0) ); OUTPUT: RETVAL diff --git a/t/op/svleak.t b/t/op/svleak.t index 77ff9ae..b949e44 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -15,7 +15,7 @@ BEGIN { use Config; -plan tests => 138; +plan tests => 139; # run some code N times. If the number of SVs at the end of loop N is # greater than (N-1)*delta at the end of loop 1, we've got a leak @@ -560,3 +560,13 @@ EOF sub f { $a =~ /[^.]+$b/; } ::leak(2, 0, \&f, q{use re 'strict' shouldn't leak warning strings}); } + +# check that B::RHE->HASH does not leak +{ + package BHINT; + sub foo {} + require B; + my $op = B::svref_2object(\&foo)->ROOT->first; + sub lk { { my $d = $op->hints_hash->HASH } } + ::leak(3, 0, \&lk, q!B::RHE->HASH shoudln't leak!); +} -- 1.8.3.1