1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

fix double release on buffers

This commit is contained in:
Darien Raymond 2018-03-28 22:23:24 +02:00
parent 12181f527f
commit fa63beceb6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 26 additions and 28 deletions

View File

@ -150,11 +150,6 @@ func fetchInput(ctx context.Context, s *Session, output buf.Writer) {
defer s.Close()
newError("dispatching request to ", dest).WithContext(ctx).WriteToLog()
data, _ := s.input.ReadTimeout(time.Millisecond * 500)
if err := writer.WriteMultiBuffer(data); err != nil {
newError("failed to write first payload").Base(err).WithContext(ctx).WriteToLog()
return
}
if err := buf.Copy(s.input, writer); err != nil {
newError("failed to fetch all input").Base(err).WithContext(ctx).WriteToLog()
}

View File

@ -178,6 +178,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
return newError("failed to write response").Base(err)
}
{
payload, err := ray.InboundOutput().ReadMultiBuffer()
if err != nil {
return err
@ -185,7 +186,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
if err := responseWriter.WriteMultiBuffer(payload); err != nil {
return err
}
payload.Release()
}
if err := bufferedWriter.SetBuffered(false); err != nil {
return err

View File

@ -182,6 +182,7 @@ func transferResponse(timer signal.ActivityUpdater, session *encoding.ServerSess
bodyWriter := session.EncodeResponseBody(request, output)
{
// Optimize for small response packet
data, err := input.ReadMultiBuffer()
if err != nil {
@ -191,7 +192,7 @@ func transferResponse(timer signal.ActivityUpdater, session *encoding.ServerSess
if err := bodyWriter.WriteMultiBuffer(data); err != nil {
return err
}
data.Release()
}
if bufferedWriter, ok := output.(*buf.BufferedWriter); ok {
if err := bufferedWriter.SetBuffered(false); err != nil {

View File

@ -113,6 +113,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
}
bodyWriter := session.EncodeRequestBody(request, writer)
{
firstPayload, err := input.ReadTimeout(time.Millisecond * 500)
if err != nil && err != buf.ErrReadTimeout {
return newError("failed to get first payload").Base(err)
@ -121,7 +122,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
if err := bodyWriter.WriteMultiBuffer(firstPayload); err != nil {
return newError("failed to write first payload").Base(err)
}
firstPayload.Release()
}
}
if err := writer.SetBuffered(false); err != nil {