Skip to content

Commit 27b12a9

Browse files
uknunknownFlole998
authored andcommitted
fix memory leak - transcoding
Fixes coverity scan issues: 551230, 551229, 507422 and 507421
1 parent 1a3ca88 commit 27b12a9

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/transcoding/transcode/audio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _audio_context_channel_layout(TVHContext *self, AVDictionary **opts, AVChannelLa
8585
{
8686
const AVChannelLayout *channel_layouts =
8787
tvh_codec_profile_audio_get_channel_layouts(self->profile);
88-
AVChannelLayout ilayout;
88+
AVChannelLayout ilayout = {0};
8989
av_channel_layout_copy(&ilayout, &self->iavctx->ch_layout);
9090
AVChannelLayout olayout;
9191
av_channel_layout_default(&olayout, 0);
@@ -193,7 +193,6 @@ tvh_audio_context_open_encoder(TVHContext *self, AVDictionary **opts)
193193
"audio encoder has no suitable channel layout");
194194
return -1;
195195
}
196-
self->oavctx->ch_layout.nb_channels = self->oavctx->ch_layout.nb_channels;
197196
#else
198197
self->oavctx->channel_layout = _audio_context_channel_layout(self, opts);
199198
if (!self->oavctx->channel_layout) {

src/transcoding/transcode/hwaccels/vaapi.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ vaapi_decode_setup_context(AVCodecContext *avctx)
637637
tvherror(LS_VAAPI, "Decode: Failed to Open VAAPI device and create an AVHWDeviceContext for device: "
638638
"%s with error code: %s",
639639
ctx->hw_accel_device, av_err2str(ret));
640+
// unref self
641+
free(self);
642+
self = NULL;
640643
return ret;
641644
}
642645

@@ -645,6 +648,12 @@ vaapi_decode_setup_context(AVCodecContext *avctx)
645648
if (!avctx->hw_device_ctx) {
646649
tvherror(LS_VAAPI, "Decode: Failed to create a hardware device reference for device: %s.",
647650
ctx->hw_accel_device);
651+
// unref hw_device_ref
652+
av_buffer_unref(&self->hw_device_ref);
653+
self->hw_device_ref = NULL;
654+
// unref self
655+
free(self);
656+
self = NULL;
648657
return AVERROR(ENOMEM);
649658
}
650659
ctx->hw_accel_ictx = self;
@@ -767,13 +776,22 @@ vaapi_encode_setup_context(AVCodecContext *avctx)
767776
if ((ret = av_hwdevice_ctx_create(&self->hw_frame_ref, AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0)) < 0) {
768777
tvherror(LS_VAAPI, "Encode: Failed to open VAAPI device and create an AVHWDeviceContext for it."
769778
"Error code: %s",av_err2str(ret));
779+
// unref self
780+
free(self);
781+
self = NULL;
770782
return ret;
771783
}
772784

773785
/* set hw_frames_ctx for encoder's AVCodecContext */
774786
if ((ret = set_hwframe_ctx(avctx, self->hw_frame_ref)) < 0) {
775787
tvherror(LS_VAAPI, "Encode: Failed to set hwframe context."
776788
"Error code: %s",av_err2str(ret));
789+
// unref hw_frame_ref
790+
av_buffer_unref(&self->hw_frame_ref);
791+
self->hw_frame_ref = NULL;
792+
// unref self
793+
free(self);
794+
self = NULL;
777795
return ret;
778796
}
779797
ctx->hw_device_octx = av_buffer_ref(self->hw_frame_ref);

0 commit comments

Comments
 (0)