[FFmpeg-cvslog] doc/examples/transcode_aac: use av_samples_alloc_array_and_samples to allocate the input samples buffer and pointers
James Almer
git at videolan.org
Fri May 5 23:07:10 EEST 2023
ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Fri May 5 15:26:19 2023 -0300| [ed3691338b25108517d354dda7f6c930fec5471c] | committer: James Almer
doc/examples/transcode_aac: use av_samples_alloc_array_and_samples to allocate the input samples buffer and pointers
Fixes -Wuse-after-free warnings and simplifies code.
Signed-off-by: James Almer <jamrial at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ed3691338b25108517d354dda7f6c930fec5471c
---
doc/examples/transcode_aac.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index bb5681a7c0..cf6edc9890 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -447,26 +447,17 @@ static int init_converted_samples(uint8_t ***converted_input_samples,
int error;
/* Allocate as many pointers as there are audio channels.
- * Each pointer will later point to the audio samples of the corresponding
+ * Each pointer will point to the audio samples of the corresponding
* channels (although it may be NULL for interleaved formats).
- */
- if (!(*converted_input_samples = calloc(output_codec_context->ch_layout.nb_channels,
- sizeof(**converted_input_samples)))) {
- fprintf(stderr, "Could not allocate converted input sample pointers\n");
- return AVERROR(ENOMEM);
- }
-
- /* Allocate memory for the samples of all channels in one consecutive
+ * Allocate memory for the samples of all channels in one consecutive
* block for convenience. */
- if ((error = av_samples_alloc(*converted_input_samples, NULL,
+ if ((error = av_samples_alloc_array_and_samples(converted_input_samples, NULL,
output_codec_context->ch_layout.nb_channels,
frame_size,
output_codec_context->sample_fmt, 0)) < 0) {
fprintf(stderr,
"Could not allocate converted input samples (error '%s')\n",
av_err2str(error));
- av_freep(&(*converted_input_samples)[0]);
- free(*converted_input_samples);
return error;
}
return 0;
@@ -598,10 +589,9 @@ static int read_decode_convert_and_store(AVAudioFifo *fifo,
ret = 0;
cleanup:
- if (converted_input_samples) {
+ if (converted_input_samples)
av_freep(&converted_input_samples[0]);
- free(converted_input_samples);
- }
+ av_freep(&converted_input_samples);
av_frame_free(&input_frame);
return ret;
More information about the ffmpeg-cvslog
mailing list