[FFmpeg-devel] [PATCH v2 4/6] avformat/rtsp: check content_ptr before memory allocate

lance.lmwang at gmail.com lance.lmwang at gmail.com
Mon Dec 6 06:45:02 EET 2021


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavformat/rtsp.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 3e4a68a..b3d1e91 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1240,7 +1240,7 @@ start:
         av_strlcpy(rt->session_id, reply->session_id, sizeof(rt->session_id));
 
     content_length = reply->content_length;
-    if (content_length > 0) {
+    if (content_ptr && content_length > 0) {
         /* leave some room for a trailing '\0' (useful for simple parsing) */
         content = av_malloc(content_length + 1);
         if (!content)
@@ -1250,11 +1250,8 @@ start:
             return AVERROR(EIO);
         }
         content[content_length] = '\0';
-    }
-    if (content_ptr)
         *content_ptr = content;
-    else
-        av_freep(&content);
+    }
 
     if (request) {
         char buf[MAX_URL_SIZE];
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list