This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix leak in Perl_coresub_op()
authorDavid Mitchell <davem@iabyn.com>
Fri, 12 Apr 2019 13:06:21 +0000 (14:06 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 12 Apr 2019 14:58:04 +0000 (15:58 +0100)
This sub initially creates a new OP_COREARGS op to be made use of in the
various cases of a following switch statement. But in the specific case
of OP_SELECT, the op isn't actually used, and leaks. So don't allocate
it in this case.

The leak could be reproduced with the one-liner

    defined &{"CORE::select"};

and was causing t/op/coresubs.t to fail under Address Sanitiser.

op.c

diff --git a/op.c b/op.c
index e630ee5..63fe245 100644 (file)
--- a/op.c
+++ b/op.c
@@ -16941,7 +16941,8 @@ OP *
 Perl_coresub_op(pTHX_ SV * const coreargssv, const int code,
                       const int opnum)
 {
-    OP * const argop = newSVOP(OP_COREARGS,0,coreargssv);
+    OP * const argop = (opnum == OP_SELECT && code) ? NULL :
+                                        newSVOP(OP_COREARGS,0,coreargssv);
     OP *o;
 
     PERL_ARGS_ASSERT_CORESUB_OP;