]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Properly unmortalize the wizard after removing it from the global hash
[perl/modules/Variable-Magic.git] / Magic.xs
index 0bd0bfd2ba1d45668266d373b0d04f0c4f884abd..f9587ab60995c8bc1b322220671d55f27ac534bc 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -1028,8 +1028,17 @@ STATIC int vmg_wizard_free(pTHX_ SV *wiz, MAGIC *mg) {
   if (hv_delete(MY_CXT.wizards, buf, sprintf(buf, "%u", w->sig), 0) != wiz)
    return 0;
  }
- SvFLAGS(wiz) |= SVf_BREAK;
- FREETMPS;
+
+ /* Unmortalize the wizard to avoid it being freed in weird places. */
+ if (SvTEMP(wiz) && !SvREFCNT(wiz)) {
+  const I32 myfloor = PL_tmps_floor;
+  I32 i;
+  for (i = PL_tmps_ix; i > myfloor; --i) {
+   SV * const sv = PL_tmps_stack[i];
+   if (sv && sv == wiz)
+    PL_tmps_stack[i] = NULL;
+  }
+ }
 
  if (w->cb_data)   SvREFCNT_dec(SvRV(w->cb_data));
  if (w->cb_get)    SvREFCNT_dec(SvRV(w->cb_get));