Recycle memory earlier in error case

pull/40/head
V2Ray 2015-10-06 17:24:16 +02:00
parent 8334d5177e
commit fe7d2d8984
1 changed files with 3 additions and 0 deletions

View File

@ -11,6 +11,9 @@ const (
func ReadFrom(reader io.Reader) ([]byte, error) { func ReadFrom(reader io.Reader) ([]byte, error) {
buffer := make([]byte, bufferSize) buffer := make([]byte, bufferSize)
nBytes, err := reader.Read(buffer) nBytes, err := reader.Read(buffer)
if nBytes == 0 {
buffer = nil
}
return buffer[:nBytes], err return buffer[:nBytes], err
} }