소스 검색

Ensure write buffer is initialized before attempting to use it.

Gert Driesen 8 년 전
부모
커밋
416f7be804
1개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      src/Renci.SshNet/Sftp/SftpFileStream.cs

+ 4 - 2
src/Renci.SshNet/Sftp/SftpFileStream.cs

@@ -700,19 +700,21 @@ namespace Renci.SshNet.Sftp
                 // Setup the object for writing.
                 SetupWrite();
 
+                var writeBuffer = GetOrCreateWriteBuffer();
+
                 // Flush the current buffer if it is full.
                 if (_bufferPosition >= _writeBufferSize)
                 {
                     using (var wait = new AutoResetEvent(false))
                     {
-                        _session.RequestWrite(_handle, (ulong) (_position - _bufferPosition), _writeBuffer, 0, _bufferPosition, wait);
+                        _session.RequestWrite(_handle, (ulong) (_position - _bufferPosition), writeBuffer, 0, _bufferPosition, wait);
                     }
 
                     _bufferPosition = 0;
                 }
 
                 // Write the byte into the buffer and advance the posn.
-                _writeBuffer[_bufferPosition++] = value;
+                writeBuffer[_bufferPosition++] = value;
                 ++_position;
             }
         }