diff options
author | sfan5 <sfan5@live.de> | 2023-07-27 22:33:28 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-07-27 22:56:37 +0200 |
commit | 4c3ed843dc8bde419d8c08565159a83cee9e3b9b (patch) | |
tree | 9d6b6f67abb9d2c31f4f5a57539a37d987b9aaaa | |
parent | bb17d4483567a606ad1b494983a22cd3364e8888 (diff) | |
download | mpv-4c3ed843dc8bde419d8c08565159a83cee9e3b9b.tar.bz2 mpv-4c3ed843dc8bde419d8c08565159a83cee9e3b9b.tar.xz |
ad_spdif: fix segfault due to early deallocation
The avpkt was created once on decoder init but destroyed each time the
filter was destroyed, this obviously can't work. Move the packet alloc
to the filter init function instead.
fixes: 4574dd5dc6ff75b1fc693afceec59fbcd51ccd4c
-rw-r--r-- | audio/decode/ad_spdif.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index decd97206d..19a9b7d2f6 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -149,10 +149,13 @@ done: MP_WARN(da, "Failed to parse codec profile.\n"); } -static int init_filter(struct mp_filter *da, AVPacket *pkt) +static int init_filter(struct mp_filter *da) { struct spdifContext *spdif_ctx = da->priv; + AVPacket *pkt = spdif_ctx->avpkt = av_packet_alloc(); + MP_HANDLE_OOM(spdif_ctx->avpkt); + int profile = FF_PROFILE_UNKNOWN; int c_rate = 0; determine_codec_params(da, pkt, &profile, &c_rate); @@ -296,12 +299,14 @@ static void process(struct mp_filter *da) struct mp_aframe *out = NULL; double pts = mpkt->pts; - mp_set_av_packet(spdif_ctx->avpkt, mpkt, NULL); - spdif_ctx->avpkt->pts = spdif_ctx->avpkt->dts = 0; if (!spdif_ctx->lavf_ctx) { - if (init_filter(da, spdif_ctx->avpkt) < 0) + if (init_filter(da) < 0) goto done; + assert(spdif_ctx->avpkt); } + + mp_set_av_packet(spdif_ctx->avpkt, mpkt, NULL); + spdif_ctx->avpkt->pts = spdif_ctx->avpkt->dts = 0; spdif_ctx->out_buffer_len = 0; int ret = av_write_frame(spdif_ctx->lavf_ctx, spdif_ctx->avpkt); avio_flush(spdif_ctx->lavf_ctx->pb); @@ -425,9 +430,6 @@ static struct mp_decoder *create(struct mp_filter *parent, return NULL; } - spdif_ctx->avpkt = av_packet_alloc(); - MP_HANDLE_OOM(spdif_ctx->avpkt); - return &spdif_ctx->public; } |