[FFmpeg-devel] [PATCH 1/4] timefilter: Handle memory allocation failure

Michael Niedermayer michaelni at gmx.at
Fri Oct 25 13:07:50 CEST 2013


On Tue, Oct 22, 2013 at 09:33:56PM +0100, Derek Buitenhuis wrote:
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
>  libavdevice/jack_audio.c | 2 ++
>  libavdevice/timefilter.c | 8 ++++++++
>  libavdevice/timefilter.h | 2 ++
>  libavdevice/v4l2.c       | 2 ++
>  4 files changed, 14 insertions(+)
> 
> diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c
> index bd6a770..854bc3b 100644
> --- a/libavdevice/jack_audio.c
> +++ b/libavdevice/jack_audio.c
> @@ -188,6 +188,8 @@ static int start_jack(AVFormatContext *context)
>  
>      /* Create time filter */
>      self->timefilter  = ff_timefilter_new (1.0 / self->sample_rate, self->buffer_size, 1.5);
> +    if (!self->timefilter)
> +        return AVERROR(ENOMEM);

maybe missing a jack_client_close() but iam no jack user/devel


>  
>      /* Create FIFO buffers */
>      self->filled_pkts = av_fifo_alloc(FIFO_PACKETS_NUM * sizeof(AVPacket));
> diff --git a/libavdevice/timefilter.c b/libavdevice/timefilter.c
> index 424e492..b4133e0 100644
> --- a/libavdevice/timefilter.c
> +++ b/libavdevice/timefilter.c
> @@ -49,6 +49,10 @@ TimeFilter *ff_timefilter_new(double time_base,
>  {
>      TimeFilter *self       = av_mallocz(sizeof(TimeFilter));
>      double o               = 2 * M_PI * bandwidth * period * time_base;
> +
> +    if (!self)
> +        return NULL;
> +
>      self->clock_period     = time_base;
>      self->feedback2_factor = qexpneg(M_SQRT2 * o);
>      self->feedback3_factor = qexpneg(o * o) / period;
> @@ -121,6 +125,10 @@ int main(void)
>                      for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) {
>                          double error   = 0;
>                          TimeFilter *tf = ff_timefilter_new(1, par0, par1);
> +                        if (!tf) {
> +                            printf("Could not alocate memory for timefilter.\n");
> +                            exit(1);
> +                        }
>                          for (i = 0; i < SAMPLES; i++) {
>                              double filtered;
>                              filtered = ff_timefilter_update(tf, samples[i], i ? (samplet[i] - samplet[i-1]) : 1);

LGTM
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131025/8de0ea07/attachment.asc>


More information about the ffmpeg-devel mailing list