From fb869aaf57d49db7377247c3a511fedbadeac70d Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Tue, 14 Jul 2015 19:41:48 +0200
Subject: [PATCH] Fixed an issue with output_to to non-files (eg, ssl).

This bug was created by the new code that allows the buffer to shrink.
---
 src/modules/_Stdio/buffer.cmod | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/modules/_Stdio/buffer.cmod b/src/modules/_Stdio/buffer.cmod
index 0bf8a64057..f18e7f9b81 100644
--- a/src/modules/_Stdio/buffer.cmod
+++ b/src/modules/_Stdio/buffer.cmod
@@ -432,7 +432,10 @@ PIKECLASS Buffer
     if( bytes > 0 )
     {
       ptrdiff_t l = 0;
-      struct pike_string *s = io_read_string( io,bytes );
+      struct pike_string *s;
+
+      io->locked_move++;
+      s = io_read_string( io,bytes );
 
       if( s )
       {
@@ -440,18 +443,23 @@ PIKECLASS Buffer
         push_string( s );
         apply_svalue( fun, 1 );
 	if (UNLIKELY(TYPEOF(Pike_sp[-1]) != PIKE_T_INT)) {
+          io->locked_move--;
 	  Pike_error("Invalid return value from write callback.\n");
 	}
         l = Pike_sp[-1].u.integer;
         pop_stack();
         if( l < 0 )
         {
+          io->locked_move--;
           io_rewind( io, bytes );
           return -1;
         }
         if( bytes > l )
+        {
           io_rewind( io, bytes-l );
+        }
       }
+      io->locked_move--;
       return l;
     }
     return -1;
-- 
GitLab