diff mbox series

[FFmpeg-devel,08/11] examples/filtering_audio: Don't use stack packet

Message ID AM7PR03MB6660A95D03D9BE5FC026007A8FCF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 3, 2021, 11:18 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 doc/examples/filtering_audio.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index 2af73a7031..7d0eb19bbe 100644
--- a/doc/examples/filtering_audio.c
+++ b/doc/examples/filtering_audio.c
@@ -215,12 +215,12 @@  static void print_frame(const AVFrame *frame)
 int main(int argc, char **argv)
 {
     int ret;
-    AVPacket packet;
+    AVPacket *packet = av_packet_alloc();
     AVFrame *frame = av_frame_alloc();
     AVFrame *filt_frame = av_frame_alloc();
 
-    if (!frame || !filt_frame) {
-        perror("Could not allocate frame");
+    if (!packet || !frame || !filt_frame) {
+        fprintf(stderr, "Could not allocate frame or packet\n");
         exit(1);
     }
     if (argc != 2) {
@@ -235,11 +235,11 @@  int main(int argc, char **argv)
 
     /* read all packets */
     while (1) {
-        if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
+        if ((ret = av_read_frame(fmt_ctx, packet)) < 0)
             break;
 
-        if (packet.stream_index == audio_stream_index) {
-            ret = avcodec_send_packet(dec_ctx, &packet);
+        if (packet->stream_index == audio_stream_index) {
+            ret = avcodec_send_packet(dec_ctx, packet);
             if (ret < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
                 break;
@@ -275,12 +275,13 @@  int main(int argc, char **argv)
                 }
             }
         }
-        av_packet_unref(&packet);
+        av_packet_unref(packet);
     }
 end:
     avfilter_graph_free(&filter_graph);
     avcodec_free_context(&dec_ctx);
     avformat_close_input(&fmt_ctx);
+    av_packet_free(&packet);
     av_frame_free(&frame);
     av_frame_free(&filt_frame);