regcomp.c: Avoid potential NULL ptr dereference
authorKarl Williamson <khw@cpan.org>
Fri, 19 Oct 2018 17:49:01 +0000 (11:49 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 20 Oct 2018 06:09:56 +0000 (00:09 -0600)
This commit cause the passed in variable to be non-NULL before
dereferencing it, as defensive coding practice.  A future commit causes
this to matter.

regcomp.c

index c6c3a5e..8f338ae 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -20277,6 +20277,9 @@ Perl_pregfree2(pTHX_ REGEXP *rx)
 
     PERL_ARGS_ASSERT_PREGFREE2;
 
+    if (! r)
+        return;
+
     if (r->mother_re) {
         ReREFCNT_dec(r->mother_re);
     } else {
@@ -20422,6 +20425,10 @@ Perl_regfree_internal(pTHX_ REGEXP * const rx)
 
     PERL_ARGS_ASSERT_REGFREE_INTERNAL;
 
+    if (! ri) {
+        return;
+    }
+
     DEBUG_COMPILE_r({
        if (!PL_colorset)
            reginitcolors();