-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to free unreferenced scalar (in 49 lines) #344
Comments
From @nwc10I've got this as short as possible. On Solaris the script attached causes Attempt to free unreferenced scalar at crashit line 29, <DATA> chunk 3. for perl5.00502, or a coredump on 5.00503, 5.00557, 5.00558 and 5.00560. The coredump is in scope.c at the line SvMAGIC(sv) = SvMAGIC(osv); which is because osv is an SV {sv_any = 0x17ae78, sv_refcnt = 2, sv_flags = 255} and has garbage in the xmg_magic pointer (0x200) which SEGVs when deferenced I've used a watchpoint to track what happened to this SV at osv, and last #0 0xc3a90 in Perl_sv_free (sv=0x17ae60) at sv.c:3170 The script is a paired down HTML (plus other stuff) parser, and the bug goes I can probably work around the problem, but it would be nice to blat the bug. I've just tried the script on BSDI and doesn't crash. Hmm. Maybe it's Solaris Nicholas Clark sub tag { # input ($coderef,$text,$inpre,$ifnest,$varnest,$tagnest) # input ($coderef,$text,$inpre,$ifnest,$varnest,$tagnest,$coderef) while (<DATA>) { __DATA__ Perl Info
|
From @hvds[Too late for 5.8.0, sorry.] Nicholas Clark once wrote: <giggle> This script: Fixing that still leaves the 'attempt to free' problems in the original I note that this test case still coredumps when run with '-Ds', though The patch below breaks out the code it wants to goto, so that we can This patch requires 'make regen_headers'. Hugo Inline Patch--- embed.fnc.old Tue Jul 16 05:02:57 2002
+++ embed.fnc Thu Jul 18 15:30:20 2002
@@ -1190,6 +1190,7 @@
#endif
#if defined(PERL_IN_SCOPE_C) || defined(PERL_DECL_PROT)
+s |void |restore_sv |SV *value|SV **ptr
s |SV* |save_scalar_at |SV **sptr
#endif
--- scope.c.old Sun May 19 02:32:24 2002
+++ scope.c Thu Jul 18 15:32:35 2002
@@ -654,6 +654,43 @@
return start;
}
+void S_restore_sv(SV *value, SV **ptr) {
+ SV *sv = *ptr;
+ DEBUG_S(PerlIO_printf(Perl_debug_log,
+ "restore svref: %p %p:%s -> %p:%s\n",
+ ptr, sv, SvPEEK(sv), value, SvPEEK(value)));
+ if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
+ SvTYPE(sv) != SVt_PVGV)
+ {
+ (void)SvUPGRADE(value, SvTYPE(sv));
+ SvMAGIC(value) = SvMAGIC(sv);
+ SvFLAGS(value) |= SvMAGICAL(sv);
+ SvMAGICAL_off(sv);
+ SvMAGIC(sv) = 0;
+ }
+ /* XXX This branch is pretty bogus. This code irretrievably
+ * clears(!) the magic on the SV (either to avoid further
+ * croaking that might ensue when the SvSETMAGIC() below is
+ * called, or to avoid two different SVs pointing at the same
+ * SvMAGIC()). This needs a total rethink. --GSAR */
+ else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
+ SvTYPE(value) != SVt_PVGV)
+ {
+ SvFLAGS(value) |= (SvFLAGS(value) &
+ (SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+ SvMAGICAL_off(value);
+ /* XXX this is a leak when we get here because the
+ * mg_get() in save_scalar_at() croaked */
+ SvMAGIC(value) = 0;
+ }
+ SvREFCNT_dec(sv);
+ *ptr = value;
+ PL_localizing = 2;
+ SvSETMAGIC(value);
+ PL_localizing = 0;
+ SvREFCNT_dec(value);
+}
+
void
Perl_leave_scope(pTHX_ I32 base)
{
@@ -681,9 +718,9 @@
case SAVEt_SV: /* scalar reference */
value = (SV*)SSPOPPTR;
gv = (GV*)SSPOPPTR;
- ptr = &GvSV(gv);
+ restore_sv(value, (SV**)&GvSV(gv));
SvREFCNT_dec(gv);
- goto restore_sv;
+ break;
case SAVEt_GENERIC_PVREF: /* generic pv */
str = (char*)SSPOPPTR;
ptr = SSPOPPTR;
@@ -714,42 +751,7 @@
break;
case SAVEt_SVREF: /* scalar reference */
value = (SV*)SSPOPPTR;
- ptr = SSPOPPTR;
- restore_sv:
- sv = *(SV**)ptr;
- DEBUG_S(PerlIO_printf(Perl_debug_log,
- "restore svref: %p %p:%s -> %p:%s\n",
- ptr, sv, SvPEEK(sv), value, SvPEEK(value)));
- if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
- SvTYPE(sv) != SVt_PVGV)
- {
- (void)SvUPGRADE(value, SvTYPE(sv));
- SvMAGIC(value) = SvMAGIC(sv);
- SvFLAGS(value) |= SvMAGICAL(sv);
- SvMAGICAL_off(sv);
- SvMAGIC(sv) = 0;
- }
- /* XXX This branch is pretty bogus. This code irretrievably
- * clears(!) the magic on the SV (either to avoid further
- * croaking that might ensue when the SvSETMAGIC() below is
- * called, or to avoid two different SVs pointing at the same
- * SvMAGIC()). This needs a total rethink. --GSAR */
- else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
- SvTYPE(value) != SVt_PVGV)
- {
- SvFLAGS(value) |= (SvFLAGS(value) &
- (SVp_NOK|SVp_POK)) >> PRIVSHIFT;
- SvMAGICAL_off(value);
- /* XXX this is a leak when we get here because the
- * mg_get() in save_scalar_at() croaked */
- SvMAGIC(value) = 0;
- }
- SvREFCNT_dec(sv);
- *(SV**)ptr = value;
- PL_localizing = 2;
- SvSETMAGIC(value);
- PL_localizing = 0;
- SvREFCNT_dec(value);
+ restore_sv(value, (SV**)SSPOPPTR);
break;
case SAVEt_AV: /* array reference */
av = (AV*)SSPOPPTR;
@@ -951,8 +953,9 @@
if (sv && sv != &PL_sv_undef) {
if (SvTIED_mg((SV*)av, PERL_MAGIC_tied))
(void)SvREFCNT_inc(sv);
+ restore_sv(value, (SV**)ptr);
SvREFCNT_dec(av);
- goto restore_sv;
+ break;
}
}
SvREFCNT_dec(av);
@@ -969,9 +972,10 @@
ptr = &HeVAL((HE*)ptr);
if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied))
(void)SvREFCNT_inc(*(SV**)ptr);
- SvREFCNT_dec(hv);
SvREFCNT_dec(sv);
- goto restore_sv;
+ restore_sv(value, (SV**)ptr);
+ SvREFCNT_dec(hv);
+ break;
}
}
SvREFCNT_dec(hv);
--- t/op/local.t.old Mon May 6 17:36:23 2002
+++ t/op/local.t Thu Jul 18 15:38:00 2002
@@ -1,6 +1,6 @@
#!./perl
-print "1..75\n";
+print "1..76\n";
sub foo {
local($a, $b) = @_;
@@ -257,3 +257,10 @@
print "not " if exists $h{'z'}; print "ok 73\n";
print "not " if exists $ENV{_A_}; print "ok 74\n";
print "not " if exists $ENV{_B_}; print "ok 75\n";
+
+{
+ # [perl #1176] Attempt to free unreferenced scalar (in 49 lines)
+ sub localiser { local $_[0] }
+ localiser();
+ print "ok 76\n";
+} |
From @nwc10On Thu, Jul 18, 2002 at 05:01:57PM -0000, Hugo van der Sanden wrote:
On Thu, Jul 18, 2002 at 06:06:25PM +0100, Hugo van der Sanden wrote:
Would it be possible for RT not to change the message ID on the messages Or does RT rely on message IDs, and really really need to send out its
That was August 1999, or thereabouts, I think. That bug is the most
Hrumph. It took me ages to get the test case down to 49 lines.
and now you've got it down to 1 slightly long line :-(
This is already way too scary for me.
Sounds like we ought to work out a way of running the regression tests with
Nicholas Clark |
From @rspierThat particular message was not supposed to be sent out, the first Moving forward (from yesterday) the only messages that RT should send -R Nicholas Clark writes:
|
@iabyn - Status changed from 'open' to 'resolved' |
From The RT System itselfthis still causes attempt to free unreferenced scalar in bleadperl DEVEL7093 |
Migrated from rt.perl.org#1176 (status was 'resolved')
Searchable as RT1176$
The text was updated successfully, but these errors were encountered: