perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: [mp2] pool object dependant methods insanity
Date Mon, 27 Dec 2004 04:22:46 GMT

> I still have a problem with APR::Pool->new->new, trying to figure out 
> how to hang APR::Pool magic on APR::Pool objects themselves. At the 
> moment things crash badly, after mg_free call.

This case:


was really tricky, as we have a special tricky case here. We hang the 
parent object's pool on the child, and when the child is getting 
destroyed, the parent pool gets destroyed during mg_free, which internally 
(via libapr) nukes the child pool, but APR::Pool doesn't know about this 
(since it already verified that it has to free the child, but the rug was 
pulled after that) and contines freeing the child. So by manually 
unwinding the magic and postponing the moment the parent goes out of 
scope, this seems to work:

+    MAGIC *mg = mg_find(acct->sv, PERL_MAGIC_ext);                  \
+    if (mg && mg->mg_obj) {                                         \
+        sv_2mortal(mg->mg_obj);                                     \
+        mg->mg_obj = Nullsv;                                        \
+        mg->mg_flags &= ~MGf_REFCOUNTED;                            \
+    }                                                               \
+    mg_free(acct->sv);                                              \
+    SvIVX(acct->sv) = 0;                                            \

This APR::Pool is really a marvel of twisted logic, and is getting more 
and more complicated. It just shows how hard it is to mix two unrelated 
memory management systems.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message