diff mbox series

[FFmpeg-devel,1/5] avformat/udp: add memory alloc checks

Message ID 1609947331-6849-1-git-send-email-lance.lmwang@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/5] avformat/udp: add memory alloc checks | expand

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

Lance Wang Jan. 6, 2021, 3:35 p.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

Marton Balint Jan. 6, 2021, 8:39 p.m. UTC | #1
On Wed, 6 Jan 2021, 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 13c346a..d33e4d6 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -892,6 +892,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>
>         /* start the task going */
>         s->fifo = av_fifo_alloc(s->circular_buffer_size);
> +        if (!s->fifo) {
> +            av_log(h, AV_LOG_ERROR, "av_fifo_alloc failed\n");
> +            goto fail;
> +        }

This looks good in principal, but I'd rather not log error messages for 
simple ENOMEM cases. I'd perfer if you could forward the ENOMEM error as a 
function return value and remove the error message.

Thanks,
Marton

>         ret = pthread_mutex_init(&s->mutex, NULL);
>         if (ret != 0) {
>             av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
> -- 
> 1.8.3.1
>
> _______________________________________________
> 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".
Lance Wang Jan. 7, 2021, 1:28 a.m. UTC | #2
On Wed, Jan 06, 2021 at 09:39:17PM +0100, Marton Balint wrote:
> 
> 
> On Wed, 6 Jan 2021, 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 13c346a..d33e4d6 100644
> > --- a/libavformat/udp.c
> > +++ b/libavformat/udp.c
> > @@ -892,6 +892,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> > 
> >         /* start the task going */
> >         s->fifo = av_fifo_alloc(s->circular_buffer_size);
> > +        if (!s->fifo) {
> > +            av_log(h, AV_LOG_ERROR, "av_fifo_alloc failed\n");
> > +            goto fail;
> > +        }
> 
> This looks good in principal, but I'd rather not log error messages for
> simple ENOMEM cases. I'd perfer if you could forward the ENOMEM error as a
> function return value and remove the error message.

OK, I'll had to change more code and return the error code for the function first.

> 
> Thanks,
> Marton
> 
> >         ret = pthread_mutex_init(&s->mutex, NULL);
> >         if (ret != 0) {
> >             av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
> > -- 
> > 1.8.3.1
> > 
> > _______________________________________________
> > 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".
> _______________________________________________
> 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 13c346a..d33e4d6 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -892,6 +892,10 @@  static int udp_open(URLContext *h, const char *uri, int flags)
 
         /* start the task going */
         s->fifo = av_fifo_alloc(s->circular_buffer_size);
+        if (!s->fifo) {
+            av_log(h, AV_LOG_ERROR, "av_fifo_alloc failed\n");
+            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));