diff mbox series

[FFmpeg-devel,v2,2/3] avformat/udp: add memory alloc checks

Message ID 1610016199-29309-2-git-send-email-lance.lmwang@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,v2,1/3] avformat/udp: return the error code instead of generic EIO
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Limin Wang Jan. 7, 2021, 10:43 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/udp.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Chad Fraleigh Jan. 8, 2021, 1:32 a.m. UTC | #1
On 1/7/2021 2:43 AM, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>   libavformat/udp.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 798b789..e6d1235 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -891,6 +891,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>       if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) {
>           /* start the task going */
>           s->fifo = av_fifo_alloc(s->circular_buffer_size);
> +        if (s->fifo) {
> +            ret = AVERROR(ENOMEM);
> +            goto fail;
> +        }

Is this suppose to be  "if (!s->fifo)"  [i.e. fail on NULL] instead?


>           ret = pthread_mutex_init(&s->mutex, NULL);
>           if (ret != 0) {
>               av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
>
Limin Wang Jan. 8, 2021, 5:55 a.m. UTC | #2
On Thu, Jan 07, 2021 at 05:32:35PM -0800, Chad Fraleigh wrote:
> 
> 
> On 1/7/2021 2:43 AM, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >   libavformat/udp.c | 4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > diff --git a/libavformat/udp.c b/libavformat/udp.c
> > index 798b789..e6d1235 100644
> > --- a/libavformat/udp.c
> > +++ b/libavformat/udp.c
> > @@ -891,6 +891,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> >       if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) {
> >           /* start the task going */
> >           s->fifo = av_fifo_alloc(s->circular_buffer_size);
> > +        if (s->fifo) {
> > +            ret = AVERROR(ENOMEM);
> > +            goto fail;
> > +        }
> 
> Is this suppose to be  "if (!s->fifo)"  [i.e. fail on NULL] instead?

yes, it lost accidently when I solve the code conflict. Will fix it, thx.

> 
> 
> >           ret = pthread_mutex_init(&s->mutex, NULL);
> >           if (ret != 0) {
> >               av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
> > 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 798b789..e6d1235 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -891,6 +891,10 @@  static int udp_open(URLContext *h, const char *uri, int flags)
     if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) {
         /* start the task going */
         s->fifo = av_fifo_alloc(s->circular_buffer_size);
+        if (s->fifo) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
         ret = pthread_mutex_init(&s->mutex, NULL);
         if (ret != 0) {
             av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));