mirror of
https://github.com/ossrs/srs.git
synced 2026-10-24 09:59:20 +03:00
## 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>