sdp: Check theora colorspace before producing the configuration string

Message ID 1386973777-83023-1-git-send-email-martin@martin.st
State Committed
Commit 6451c8853a07ff2e28bda950fb5e83fcf88c5cf4
Headers show

Commit Message

Martin Storsjö Dec. 13, 2013, 10:29 p.m.
This avoids a memory leak (or having to worry about freeing the
config string) if the colorspace isn't accepted.
---
 libavformat/sdp.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Luca Barbato Dec. 13, 2013, 10:30 p.m. | #1
On 13/12/13 23:29, Martin Storsjö wrote:
> This avoids a memory leak (or having to worry about freeing the
> config string) if the colorspace isn't accepted.
> ---
>  libavformat/sdp.c |   14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

Ok obviously =)

lu

Patch

diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index 186f83b..ec7e2f4 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -513,13 +513,6 @@  static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
             break;
         case AV_CODEC_ID_THEORA: {
             const char *pix_fmt;
-            if (c->extradata_size)
-                config = xiph_extradata2config(c);
-            else
-                av_log(c, AV_LOG_ERROR, "Theora configuation info missing\n");
-            if (!config)
-                return NULL;
-
             switch (c->pix_fmt) {
             case AV_PIX_FMT_YUV420P:
                 pix_fmt = "YCbCr-4:2:0";
@@ -535,6 +528,13 @@  static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
                 return NULL;
             }
 
+            if (c->extradata_size)
+                config = xiph_extradata2config(c);
+            else
+                av_log(c, AV_LOG_ERROR, "Theora configuation info missing\n");
+            if (!config)
+                return NULL;
+
             av_strlcatf(buff, size, "a=rtpmap:%d theora/90000\r\n"
                                     "a=fmtp:%d delivery-method=inline; "
                                     "width=%d; height=%d; sampling=%s; "