APR::Bucket->new($data);
1) If you change $data after creating the bucket, the data in the bucket is modified as well. This could lead to unexpected behavior and bugs, but with proper documentation it should probably be OK. A better solution is to turn the sv into READONLY.
2) temporary svs cause buckets corruption.
If you create a real variable, and pass it to APR::Bucket->new() it'll get its refcount incremented to ensure that it won't be destroyed by Perl. The problem is when new() gets the same SV to create different buckets. This is the case with temporary SVs, Perl will re-use the same sv again and again when it needs a temp. As the following code demonstrates calling APR::Bucket->new(lc $data) passes a temp SV to
new() and it'll store the same sv address for different buckets. so the data of the last bucket will corrupt the data of all the previous buckets, since they share the PV slot. Observe for youself:
use strict; use warnings;
use blib; use Apache2;
use APR::Bucket; use Devel::Peek;
my @buckets = (func("ABCD"), func("EF"));
for my $b (@buckets) {
$b->read($_);
Dump $_;
}sub func {
my $data = shift;
return APR::Bucket->new(lc $data);
}SV = PV(0x81262c4) at 0x804cbd4 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x80d9a70 "ef\0d"\0 CUR = 4 LEN = 5 SV = PV(0x81262c4) at 0x804cbd4 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x80d9a70 "ef"\0 CUR = 2 LEN = 5
As you can see the sv and pv are at the same address and the first buckets original data "abcd" was overwritten by "ef\0d".
It took me some time to bring this bug to a simple test case. Now I'm pondering on how to fix it w/o adding an overhead of copying the PV slot away (which in most cases will be a waste). Ideas are more than welcome.
-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
