Check if reallocation of PL_linestr is necessary before doing it.
Florian Ragwitz [Sat, 4 Oct 2008 13:18:02 +0000 (13:18 +0000)]
That way memory curruption caused by SvGROW on a PL_linestr comming from perl
-e goes away.

Declare.xs

index 142a816..7bff0c9 100644 (file)
@@ -118,10 +118,11 @@ void dd_set_linestr(pTHX_ char* new_value) {
   int new_len = strlen(new_value);
   char* old_linestr = SvPVX(PL_linestr);
 
-  SvGROW(PL_linestr, new_len);
-
-  if (SvPVX(PL_linestr) != old_linestr)
+  if (SvLEN(PL_linestr) < new_len) {
     croak("forced to realloc PL_linestr for line %s, bailing out before we crash harder", SvPVX(PL_linestr));
+  }
+
+  SvGROW(PL_linestr, new_len);
 
   memcpy(SvPVX(PL_linestr), new_value, new_len+1);