This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Test that code block exists before cleaning
authorKarl Williamson <khw@cpan.org>
Fri, 19 Oct 2018 17:47:05 +0000 (11:47 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 20 Oct 2018 06:09:56 +0000 (00:09 -0600)
This is defensive coding progress, to avoid dereferencing a NULL ptr.

perl.h
regcomp.c

diff --git a/perl.h b/perl.h
index e6ab70f..f7e8100 100644 (file)
--- a/perl.h
+++ b/perl.h
     Perl_pregfree(aTHX_ (prog))
 
 #define CALLREGFREE_PVT(prog) \
-    if(prog) RX_ENGINE(prog)->rxfree(aTHX_ (prog))
+    if(prog && RX_ENGINE(prog)) RX_ENGINE(prog)->rxfree(aTHX_ (prog))
 
 #define CALLREG_NUMBUF_FETCH(rx,paren,usesv)                                \
     RX_ENGINE(rx)->numbered_buff_FETCH(aTHX_ (rx),(paren),(usesv))
index 04e2228..c6c3a5e 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6328,8 +6328,10 @@ S_free_codeblocks(pTHX_ struct reg_code_blocks *cbs)
         return;
     for (n = 0; n < cbs->count; n++) {
         REGEXP *rx = cbs->cb[n].src_regex;
-        cbs->cb[n].src_regex = NULL;
-        SvREFCNT_dec(rx);
+        if (rx) {
+            cbs->cb[n].src_regex = NULL;
+            SvREFCNT_dec_NN(rx);
+        }
     }
     Safefree(cbs->cb);
     Safefree(cbs);