[2/3] rdt: Check the return value of avformat_open

Message ID 1320618479-75827-2-git-send-email-martin@martin.st
State Committed
Commit ed307e2659f2db81a434afece905383fdceb9b6e
Headers show

Commit Message

Martin Storsjö Nov. 6, 2011, 10:27 p.m.
If it failed, return NULL. This avoids trying to use an
half-initialized RDTDemuxContext.
---
 libavformat/rdt.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

Comments

Ronald Bultje Nov. 7, 2011, 12:48 a.m. | #1
Hi,

On Sun, Nov 6, 2011 at 2:27 PM, Martin Storsjö <martin@martin.st> wrote:
> If it failed, return NULL. This avoids trying to use an
> half-initialized RDTDemuxContext.
> ---
>  libavformat/rdt.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/libavformat/rdt.c b/libavformat/rdt.c
> index 3f161f6..f492805 100644
> --- a/libavformat/rdt.c
> +++ b/libavformat/rdt.c
> @@ -524,7 +524,11 @@ rdt_new_context (void)
>  {
>     PayloadContext *rdt = av_mallocz(sizeof(PayloadContext));
>
> -    avformat_open_input(&rdt->rmctx, "", &ff_rdt_demuxer, NULL);
> +    int ret = avformat_open_input(&rdt->rmctx, "", &ff_rdt_demuxer, NULL);
> +    if (ret < 0) {
> +        av_free(rdt);
> +        return NULL;
> +    }
>
>     return rdt;
>  }

OK.

Ronald

Patch

diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index 3f161f6..f492805 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -524,7 +524,11 @@  rdt_new_context (void)
 {
     PayloadContext *rdt = av_mallocz(sizeof(PayloadContext));
 
-    avformat_open_input(&rdt->rmctx, "", &ff_rdt_demuxer, NULL);
+    int ret = avformat_open_input(&rdt->rmctx, "", &ff_rdt_demuxer, NULL);
+    if (ret < 0) {
+        av_free(rdt);
+        return NULL;
+    }
 
     return rdt;
 }