From 3aa302f2583b14bc2138fd10fa34aa91388c823d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 5 Dec 2016 05:00:32 -0500 Subject: [PATCH] TT#5566 memory allocation fixes Change-Id: I7b247c591d3f35b2b767fd9faec6d1b09f52b871 --- recording-daemon/metafile.c | 2 +- recording-daemon/mix.c | 19 ++++++++++++++++--- recording-daemon/output.c | 2 ++ recording-daemon/stream.c | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index 453c6087d..55b66f995 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -36,8 +36,8 @@ static void meta_free(void *ptr) { stream_free(stream); } g_ptr_array_free(mf->streams, TRUE); - g_slice_free1(sizeof(*mf), mf); g_hash_table_destroy(mf->ssrc_hash); + g_slice_free1(sizeof(*mf), mf); } diff --git a/recording-daemon/mix.c b/recording-daemon/mix.c index dca504ddb..65f29ddb6 100644 --- a/recording-daemon/mix.c +++ b/recording-daemon/mix.c @@ -22,6 +22,7 @@ struct mix_s { AVFilterContext *amix_ctx; AVFilterContext *sink_ctx; unsigned int next_idx; + AVFrame *sink_frame; AVAudioResampleContext *avresample; AVFrame *swr_frame; @@ -44,12 +45,15 @@ static void mix_shutdown(mix_t *mix) { mix->src_ctxs[i] = NULL; } + avresample_free(&mix->avresample); avfilter_graph_free(&mix->graph); } void mix_destroy(mix_t *mix) { mix_shutdown(mix); + av_frame_free(&mix->sink_frame); + av_frame_free(&mix->swr_frame); g_slice_free1(sizeof(*mix), mix); } @@ -152,6 +156,7 @@ mix_t *mix_new() { mix_t *mix = g_slice_alloc0(sizeof(*mix)); mix->clockrate = -1; mix->channels = -1; + mix->sink_frame = av_frame_alloc(); return mix; } @@ -229,6 +234,7 @@ err: } +// frees the frame passed to it int mix_add(mix_t *mix, AVFrame *frame, unsigned int idx, output_t *output) { const char *err; @@ -244,8 +250,10 @@ int mix_add(mix_t *mix, AVFrame *frame, unsigned int idx, output_t *output) { if (av_buffersrc_add_frame(mix->src_ctxs[idx], frame)) goto err; + av_frame_free(&frame); + while (1) { - int ret = av_buffersink_get_frame(mix->sink_ctx, frame); + int ret = av_buffersink_get_frame(mix->sink_ctx, mix->sink_frame); err = "failed to get frame from mixer"; if (ret < 0) { if (ret == AVERROR(EAGAIN)) @@ -253,9 +261,13 @@ int mix_add(mix_t *mix, AVFrame *frame, unsigned int idx, output_t *output) { else goto err; } - frame = mix_resample_frame(mix, frame); + frame = mix_resample_frame(mix, mix->sink_frame); + + ret = output_add(output, mix->sink_frame); + + av_frame_unref(mix->sink_frame); - if (output_add(output, frame)) + if (ret) return -1; } @@ -263,5 +275,6 @@ int mix_add(mix_t *mix, AVFrame *frame, unsigned int idx, output_t *output) { err: ilog(LOG_ERR, "Failed to add frame to mixer: %s", err); + av_frame_free(&frame); return -1; } diff --git a/recording-daemon/output.c b/recording-daemon/output.c index 440010039..45f5403a6 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -119,6 +119,8 @@ static int output_flush(output_t *output) { output->fifo_pts += output->frame->nb_samples; output->mux_dts = output->avpkt.dts + 1; // min next expected dts + + av_packet_unref(&output->avpkt); } while (keep_going); } diff --git a/recording-daemon/stream.c b/recording-daemon/stream.c index 974de11a0..c87e2b526 100644 --- a/recording-daemon/stream.c +++ b/recording-daemon/stream.c @@ -28,6 +28,7 @@ void stream_free(stream_t *stream) { static void stream_handler(handler_t *handler) { stream_t *stream = handler->ptr; + unsigned char *buf = NULL; //dbg("poll event for %s", stream->name); @@ -45,7 +46,7 @@ static void stream_handler(handler_t *handler) { + FF_INPUT_BUFFER_PADDING_SIZE #endif ; - unsigned char *buf = malloc(alloclen); + buf = malloc(alloclen); int ret = read(stream->fd, buf, maxbuflen); if (ret == 0) { ilog(LOG_INFO, "EOF on stream %s", stream->name); @@ -65,6 +66,7 @@ static void stream_handler(handler_t *handler) { out: pthread_mutex_unlock(&stream->lock); + free(buf); }