summaryrefslogtreecommitdiff
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>2013-10-22 17:46:37 (GMT)
committer Derek Buitenhuis <derek.buitenhuis@gmail.com>2013-10-27 19:14:23 (GMT)
commit6ef30976e00a07ed7c6db54102d2ba50d24c876c (patch)
treeec4f00cf039688f9bb35f6e475dbc3327c32a76d
parentfc7be7ddf3dea2f95d2d8bedde2fed44b4f469f2 (diff)
downloadffmpeg-6ef30976e00a07ed7c6db54102d2ba50d24c876c.zip
ffmpeg-6ef30976e00a07ed7c6db54102d2ba50d24c876c.tar.gz
ffmpeg-6ef30976e00a07ed7c6db54102d2ba50d24c876c.tar.bz2
timefilter: Handle memory allocation failure
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat
-rw-r--r--libavdevice/jack_audio.c4
-rw-r--r--libavdevice/timefilter.c8
-rw-r--r--libavdevice/timefilter.h2
-rw-r--r--libavdevice/v4l2.c2
4 files changed, 16 insertions, 0 deletions
diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c
index bd6a770..5ba6731 100644
--- a/libavdevice/jack_audio.c
+++ b/libavdevice/jack_audio.c
@@ -188,6 +188,10 @@ 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) {
+ 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 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);
diff --git a/libavdevice/timefilter.h b/libavdevice/timefilter.h
index 6662959..cb3d0a7 100644
--- a/libavdevice/timefilter.h
+++ b/libavdevice/timefilter.h
@@ -58,6 +58,8 @@ typedef struct TimeFilter TimeFilter;
* @param period expected update interval, in input units
* @param brandwidth filtering bandwidth, in Hz
*
+ * @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
*/
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 1b2ede4..cb962b7 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -455,6 +455,8 @@ static int init_convert_timestamp(AVFormatContext *ctx, int64_t ts)
av_log(ctx, AV_LOG_INFO, "Detected monotonic timestamps, converting\n");
/* microseconds instead of seconds, MHz instead of Hz */
s->timefilter = ff_timefilter_new(1, period, 1.0E-6);
+ if (!s->timefilter)
+ return AVERROR(ENOMEM);
s->ts_mode = V4L_TS_CONVERT_READY;
return 0;
}