summaryrefslogtreecommitdiff
path: root/ext/File-Glob
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-04-27 17:08:15 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-12-09 18:47:19 -0800
commitf01818e214428dd68e3cb9d9c7cead608216ffa5 (patch)
tree76c56033d6ef1f5d40dba7050520b91b87618fed /ext/File-Glob
parentc619428f3ddd8b400d932fe55a95dbfa57c647fc (diff)
downloadperl-f01818e214428dd68e3cb9d9c7cead608216ffa5.tar.gz
File::Glob: Don’t use the magic 2nd arg to glob
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.
Diffstat (limited to 'ext/File-Glob')
-rw-r--r--ext/File-Glob/Glob.pm2
-rw-r--r--ext/File-Glob/Glob.xs18
2 files changed, 9 insertions, 11 deletions
diff --git a/ext/File-Glob/Glob.pm b/ext/File-Glob/Glob.pm
index 89dd420c91..ef82389e24 100644
--- a/ext/File-Glob/Glob.pm
+++ b/ext/File-Glob/Glob.pm
@@ -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;
}
diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
index d74e7a4965..252c2eddb0 100644
--- a/ext/File-Glob/Glob.xs
+++ b/ext/File-Glob/Glob.xs
@@ -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;