From: Vincent Pit <vince@profvince.com>
Date: Fri, 24 Sep 2010 17:08:21 +0000 (+0200)
Subject: Describe why we don't have to guard against PL_dirty in vmg_mgwiz_free()
X-Git-Tag: v0.44~3
X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=b14820447a917677db201d0c116a061547269fd3;p=perl%2Fmodules%2FVariable-Magic.git

Describe why we don't have to guard against PL_dirty in vmg_mgwiz_free()
---

diff --git a/Magic.xs b/Magic.xs
index e336abe..9aabb41 100644
--- a/Magic.xs
+++ b/Magic.xs
@@ -449,6 +449,15 @@ STATIC void vmg_mgwiz_free(pTHX_ MGWIZ *w) {
  if (!w)
   return;
 
+ /* We reach this point in dirty state when ptable_free() is called from the
+  * atexit cleanup callback, and that the global table still holds a live
+  * wizard. This happens before all the SV bodies are freed, so all the wizard
+  * callbacks are still alive (as they are referenced by the undead wizard).
+  * Hence it is safe to decrement their refcount. Later on, the wizard free
+  * callback itself will trigger when the wizard body is reaped, but it will
+  * be skipped as it guards against dirty state - which is good since nothing
+  * has to be done anymore at that point. */
+
  SvREFCNT_dec(w->cb_data);
  SvREFCNT_dec(w->cb_get);
  SvREFCNT_dec(w->cb_set);