1
0
mirror of https://github.com/ossrs/srs.git synced 2026-10-24 09:59:20 +03:00
Files
sevico 69cbfe5e97 Proxy: Fix resource leak in ParseBody. v8.0.26 (#4659)
## Problem

`ParseBody` in `internal/utils/utils.go` defers `r.Close()` only after
`io.ReadAll(r)` succeeds. If `io.ReadAll` returns an error, the function
returns before registering the deferred close, so the request/body
reader is left open.

```go
func ParseBody(r io.ReadCloser, v interface{}) error {
    b, err := io.ReadAll(r)
    if err != nil {
        return errors.Wrapf(err, "read body") // r is not closed on this path
    }
    defer r.Close()
```

## Solution

Move `defer r.Close()` to the top of `ParseBody`, before reading the
body, so all return paths close the reader.

```go
func ParseBody(r io.ReadCloser, v interface{}) error {
    defer r.Close()

    b, err := io.ReadAll(r)
```

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2026-08-17 21:36:23 -04:00
..