From e60e73553260c3f23d20ae55380e09bdca2819b6 Mon Sep 17 00:00:00 2001 From: macbookpro Date: Sun, 6 Jan 2019 22:34:29 +0800 Subject: [PATCH] fix a crash risk --- rtsp/rtsp-client.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/rtsp/rtsp-client.go b/rtsp/rtsp-client.go index 2454bf5c..02abdc6c 100644 --- a/rtsp/rtsp-client.go +++ b/rtsp/rtsp-client.go @@ -235,17 +235,22 @@ func (client *RTSPClient) requestStream(timeout time.Duration) (err error) { headers = make(map[string]string) headers["Accept"] = "application/sdp" resp, err = client.Request("DESCRIBE", headers) - authorization, _ := client.checkAuth("DESCRIBE", resp) - if len(authorization) > 0 { - headers := make(map[string]string) - headers["Authorization"] = authorization - headers["Accept"] = "application/sdp" - resp, err = client.Request("DESCRIBE", headers) - } if err != nil { - return err + if resp != nil { + authorization, _ := client.checkAuth("DESCRIBE", resp) + if len(authorization) > 0 { + headers := make(map[string]string) + headers["Authorization"] = authorization + headers["Accept"] = "application/sdp" + resp, err = client.Request("DESCRIBE", headers) + } + if err != nil { + return err + } + } else { + return err + } } - _sdp, err := sdp.ParseString(resp.Body) if err != nil { return err