diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2013-10-22 21:46:37 +0400 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2013-10-29 15:40:04 +0400 |
commit | 327c439f811a89d774db9a86f72951d295193e5f (patch) | |
tree | 677c7e245a96657e00f96613a38f868d2e4d8743 /libavdevice | |
parent | e78913052263af80855590659fb0f705e8f13c8a (diff) |
timefilter: Handle memory allocation failure
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavdevice')
-rw-r--r-- | libavdevice/jack_audio.c | 4 | ||||
-rw-r--r-- | libavdevice/timefilter.c | 10 | ||||
-rw-r--r-- | libavdevice/timefilter.h | 2 |
3 files changed, 15 insertions, 1 deletions
diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c index 280f24dc48..c261514033 100644 --- a/libavdevice/jack_audio.c +++ b/libavdevice/jack_audio.c @@ -190,6 +190,10 @@ static int start_jack(AVFormatContext *context) period = (double) self->buffer_size / self->sample_rate; o = 2 * M_PI * 1.5 * period; /// bandwidth: 1.5Hz self->timefilter = ff_timefilter_new (1.0 / self->sample_rate, sqrt(2 * o), o * o); + if (!self->timefilter) { + jack_client_close(self->client); + return AVERROR(ENOMEM); + } /* 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 8b98d338f0..a49735158c 100644 --- a/libavdevice/timefilter.c +++ b/libavdevice/timefilter.c @@ -41,7 +41,11 @@ TimeFilter *ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor) { - TimeFilter *self = av_mallocz(sizeof(TimeFilter)); + TimeFilter *self = av_mallocz(sizeof(TimeFilter)); + + if (!self) + return NULL; + self->clock_period = clock_period; self->feedback2_factor = feedback2_factor; self->feedback3_factor = feedback3_factor; @@ -105,6 +109,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 allocate memory for timefilter.\n"); + exit(1); + } for (i = 0; i < SAMPLES; i++) { double filtered; filtered = ff_timefilter_update(tf, samples[i], 1); diff --git a/libavdevice/timefilter.h b/libavdevice/timefilter.h index 8cadd8b066..2235db60e3 100644 --- a/libavdevice/timefilter.h +++ b/libavdevice/timefilter.h @@ -56,6 +56,8 @@ typedef struct TimeFilter TimeFilter; * @param clock_period period of the hardware clock in seconds * (for example 1.0/44100) * + * @return a pointer to a TimeFilter struct, or NULL on error + * * For more details about these parameters and background concepts please see: * http://www.kokkinizita.net/papers/usingdll.pdf */ |