bluenviron / gortsplib

RTSP 1.0 client and server library for the Go programming language
MIT License
634 stars 177 forks source link

memory leak? #581

Open hessonsu opened 2 weeks ago

hessonsu commented 2 weeks ago

issues 337

hessonsu commented 2 weeks ago

// Unmarshal decodes an interleaved frame.
func (f *InterleavedFrame) Unmarshal(br *bufio.Reader) error {
    var header [4]byte
    _, err := io.ReadFull(br, header[:])
    if err != nil {
        return err
    }

    if header[0] != InterleavedFrameMagicByte {
        return fmt.Errorf("invalid magic byte (0x%.2x)", header[0])
    }

    // it's useless to check payloadLen since it's limited to 65535
    payloadLen := int(uint16(header[2])<<8 | uint16(header[3]))

    f.Channel = int(header[1])
    f.Payload = make([]byte, payloadLen)

    _, err = io.ReadFull(br, f.Payload)
    return err
}

Discuss, how to use this method not to request memory make([]byte, payloadLen) This increases the pressure on the GC