061319a
diff -up perl-5.10.0/ext/Storable/Storable.xs.old perl-5.10.0/ext/Storable/Storable.xs
061319a
--- perl-5.10.0/ext/Storable/Storable.xs.old	2007-12-18 11:47:07.000000000 +0100
061319a
+++ perl-5.10.0/ext/Storable/Storable.xs	2008-09-30 14:03:38.000000000 +0200
061319a
@@ -4561,7 +4561,13 @@ static SV *retrieve_overloaded(pTHX_ stc
061319a
 	 * WARNING: breaks RV encapsulation.
061319a
 	 */
061319a
 
061319a
-	sv_upgrade(rv, SVt_RV);
061319a
+	if (cname) {
061319a
+	/* No need to do anything, as rv will already be PVMG. */
061319a
+		assert (SvTYPE(rv) >= SVt_RV);
061319a
+	} else {
061319a
+		sv_upgrade(rv, SVt_RV);
061319a
+	}
061319a
+
061319a
 	SvRV_set(rv, sv);				/* $rv = \$sv */
061319a
 	SvROK_on(rv);
061319a
 
061319a
diff -up perl-5.10.0/ext/Storable/t/overload.t.old perl-5.10.0/ext/Storable/t/overload.t
061319a
--- perl-5.10.0/ext/Storable/t/overload.t.old	2007-12-18 11:47:07.000000000 +0100
061319a
+++ perl-5.10.0/ext/Storable/t/overload.t	2008-09-30 14:05:04.000000000 +0200
061319a
@@ -25,7 +25,7 @@ sub ok;
061319a
 
061319a
 use Storable qw(freeze thaw);
061319a
 
061319a
-print "1..16\n";
061319a
+print "1..20\n";
061319a
 
061319a
 package OVERLOADED;
061319a
 
061319a
@@ -59,6 +59,14 @@ sub make {
061319a
 	return $self;
061319a
 }
061319a
 
061319a
+package SCALAR_REF_TO_OVER;
061319a
+
061319a
+sub create {
061319a
+my ($class) = @_;
061319a
+my $over = bless {}, 'OVER';
061319a
+return bless \$over, $class;
061319a
+}
061319a
+
061319a
 package OVER;
061319a
 
061319a
 use overload
061319a
@@ -103,4 +111,11 @@ ok 13, $@ eq "";
061319a
 ok 14, ref ($t) eq 'REF';
061319a
 ok 15, ref ($$t) eq 'HAS_OVERLOAD';
061319a
 ok 16, $$$t eq 'snow';
061319a
+$c = SCALAR_REF_TO_OVER->create();
061319a
+# Don't segfault here
061319a
+$d = thaw freeze $c;
061319a
+ok 17, ref($c) eq 'SCALAR_REF_TO_OVER';
061319a
+ok 18, ref($d) eq 'SCALAR_REF_TO_OVER';
061319a
+ok 19, ref($$c) eq 'OVER';
061319a
+ok 20, ref($$d) eq 'OVER';
061319a
 1;