Skip to content

Commit

Permalink
Fixed a few bugs in get_caller
Browse files Browse the repository at this point in the history
If we're getting a called value from the options then we need to inc its
refcnt since we'll dec it shortly.

On perl < 5.14 where we have to call caller() from XS we also need inc the
refcnt of the returned scalar.
  • Loading branch information
autarch committed Jan 7, 2015
1 parent a16ed23 commit 924e8d4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Params/Validate/XS.xs
Expand Up @@ -296,6 +296,7 @@ get_caller(HV* options) {

if ((temp = hv_fetch(options, "called", 6, 0))) {
SvGETMAGIC(*temp);
SvREFCNT_inc(*temp);
return *temp;
}
else {
Expand Down Expand Up @@ -350,6 +351,11 @@ get_caller(HV* options) {
if (SvTYPE(caller) == SVt_NULL) {
sv_setpv(caller, "(unknown");
}

/* This will be decremented by the code that asked for this value, but
we need to do this here because the return value of caller() is
mortal and has a refcnt of 1. */
SvREFCNT_inc(caller);
#endif

return caller;
Expand Down

0 comments on commit 924e8d4

Please sign in to comment.