Skip to content

Commit d7d35eb

Browse files
committed
pp_ctl.c - refetch @inc from *INC after hook
The original value may have been freed by the time the hook returns, so we have to refetch it immediately after execution. We also move the declaration into a more minimal scope.
1 parent 1e86200 commit d7d35eb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pp_ctl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4260,14 +4260,14 @@ S_require_file(pTHX_ SV *sv)
42604260
* For searchable paths, just search @INC normally
42614261
*/
42624262
if (!tryrsfp && !(errno == EACCES && !path_searchable)) {
4263-
AV * const inc_ar = GvAVn(PL_incgv);
42644263
SSize_t inc_idx;
42654264
#ifdef VMS
42664265
if (vms_unixname)
42674266
#endif
42684267
{
42694268
SV *nsv = sv;
42704269
namesv = newSV_type(SVt_PV);
4270+
AV *inc_ar = GvAVn(PL_incgv);
42714271
for (inc_idx = 0; inc_idx <= AvFILL(inc_ar); inc_idx++) {
42724272
SV * const dirsv = *av_fetch(inc_ar, inc_idx, TRUE);
42734273

@@ -4376,6 +4376,13 @@ S_require_file(pTHX_ SV *sv)
43764376
FREETMPS;
43774377
LEAVE_with_name("call_INC_hook");
43784378

4379+
/*
4380+
It is possible that @INC has been replaced and that inc_ar
4381+
now points at a freed AV. So we have to refresh it from
4382+
the GV to be sure.
4383+
*/
4384+
inc_ar = GvAVn(PL_incgv);
4385+
43794386
/* Now re-mortalize it. */
43804387
sv_2mortal(filter_cache);
43814388

0 commit comments

Comments
 (0)