This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
File::Glob: Don’t use the magic 2nd arg to glob
authorFather Chrysostomos <sprout@cpan.org>
Sat, 28 Apr 2012 00:08:15 +0000 (17:08 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 10 Dec 2012 02:47:19 +0000 (18:47 -0800)
See the previous commit.  The same applies to File::Glob as well.

In short, the easiest way to fix a memory leak involves using the
address of the glob op rather than a special glob index.

ext/File-Glob/Glob.pm
ext/File-Glob/Glob.xs

index 89dd420..ef82389 100644 (file)
@@ -71,7 +71,7 @@ if ($^O =~ /^(?:MSWin32|VMS|os2|dos|riscos)$/) {
 # File::Glob::glob() is deprecated because its prototype is different from
 # CORE::glob() (use bsd_glob() instead)
 sub glob {
-    splice @_, 1; # don't pass PL_glob_index as flags!
+    splice @_, 1; # no flags
     goto &bsd_glob;
 }
 
index d74e7a4..252c2ed 100644 (file)
@@ -75,10 +75,8 @@ iterate(pTHX_ bool(*globber)(pTHX_ AV *entries, SV *patsv))
     SV *patsv = POPs;
     bool on_stack = FALSE;
 
-    /* assume global context if not provided one */
     SvGETMAGIC(cxixsv);
-    if (SvOK(cxixsv)) cxixpv = SvPV_nomg(cxixsv, cxixlen);
-    else cxixpv = "_G_", cxixlen = 3;
+    cxixpv = SvPV_nomg(cxixsv, cxixlen);
 
     if (!MY_CXT.x_GLOB_ENTRIES) MY_CXT.x_GLOB_ENTRIES = newHV();
     entries = (AV *)*(hv_fetch(MY_CXT.x_GLOB_ENTRIES, cxixpv, cxixlen, 1));
@@ -355,14 +353,14 @@ void
 csh_glob(...)
 PPCODE:
     /* For backward-compatibility with the original Perl function, we sim-
-     * ply take the first two arguments, regardless of how many there are.
+     * ply take the first argument, regardless of how many there are.
      */
-    if (items >= 2) SP += 2;
+    if (items) SP ++;
     else {
-       SP += items;
        XPUSHs(&PL_sv_undef);
-       if (!items) XPUSHs(&PL_sv_undef);
     }
+    XPUSHs(newSVpvn_flags((char *)&PL_op, sizeof(OP *), SVs_TEMP));
+    sv_catpvs(*SP, "_"); /* Avoid conflicts with PL_glob_index */
     PUTBACK;
     csh_glob_iter(aTHX);
     SPAGAIN;
@@ -370,12 +368,12 @@ PPCODE:
 void
 bsd_glob_override(...)
 PPCODE:
-    if (items >= 2) SP += 2;
+    if (items) SP ++;
     else {
-       SP += items;
        XPUSHs(&PL_sv_undef);
-       if (!items) XPUSHs(&PL_sv_undef);
     }
+    XPUSHs(newSVpvn_flags((char *)&PL_op, sizeof(OP *), SVs_TEMP));
+    sv_catpvs(*SP, "_"); /* Avoid conflicts with PL_glob_index */
     PUTBACK;
     iterate(aTHX_ doglob_iter_wrapper);
     SPAGAIN;