fix(*): address nullptr deref and resource leaks

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x
2026-03-07 00:00:00 +00:00
parent 4a8669b0b3
commit 7db9c18d62
8 changed files with 30 additions and 3 deletions

View File

@@ -126,7 +126,7 @@ AVPixelFormat get_encoder_default_pix_fmt(const AVCodec* encoder, AVPixelFormat
if (target_pix_fmt != AV_PIX_FMT_NONE && best_pix_fmt != target_pix_fmt) {
logger()->warn(
"Incompatible pixel format '%s' for encoder '%s'; auto-selecting format '%s'",
"Incompatible pixel format '{}' for encoder '{}'; auto-selecting format '{}'",
av_get_pix_fmt_name(target_pix_fmt),
encoder->name,
av_get_pix_fmt_name(best_pix_fmt)

View File

@@ -184,6 +184,10 @@ int FilterRealcugan::filter(AVFrame* in_frame, AVFrame** out_frame) {
// Convert ncnn::Mat to AVFrame
*out_frame = conversions::ncnn_mat_to_avframe(out_mat, out_pix_fmt_);
if (*out_frame == nullptr) {
logger()->error("Failed to convert ncnn::Mat to AVFrame");
return AVERROR(ENOMEM);
}
// Rescale PTS to encoder's time base
(*out_frame)->pts = av_rescale_q(in_frame->pts, in_time_base_, out_time_base_);

View File

@@ -124,6 +124,10 @@ int FilterRealesrgan::filter(AVFrame* in_frame, AVFrame** out_frame) {
// Convert ncnn::Mat to AVFrame
*out_frame = conversions::ncnn_mat_to_avframe(out_mat, out_pix_fmt_);
if (*out_frame == nullptr) {
logger()->error("Failed to convert ncnn::Mat to AVFrame");
return AVERROR(ENOMEM);
}
// Rescale PTS to encoder's time base
(*out_frame)->pts = av_rescale_q(in_frame->pts, in_time_base_, out_time_base_);

View File

@@ -128,6 +128,10 @@ int InterpolatorRIFE::interpolate(
// Convert ncnn::Mat to AVFrame
*out_frame = conversions::ncnn_mat_to_avframe(out_mat, out_pix_fmt_);
if (*out_frame == nullptr) {
logger()->error("Failed to convert ncnn::Mat to AVFrame");
return AVERROR(ENOMEM);
}
// Rescale PTS to encoder's time base
(*out_frame)->pts = av_rescale_q(in_frame->pts, in_time_base_, out_time_base_);

View File

@@ -44,6 +44,7 @@ int init_libplacebo(
AVFilterGraph* graph = avfilter_graph_alloc();
if (!graph) {
logger()->error("Unable to create filter graph.");
av_buffer_unref(&vk_hw_device_ctx);
return AVERROR(ENOMEM);
}
@@ -52,6 +53,7 @@ int init_libplacebo(
if (!buffersrc) {
logger()->error("Filter 'buffer' not found.");
avfilter_graph_free(&graph);
av_buffer_unref(&vk_hw_device_ctx);
return AVERROR_FILTER_NOT_FOUND;
}
@@ -90,6 +92,7 @@ int init_libplacebo(
if (ret < 0) {
logger()->error("Cannot create buffer source.");
avfilter_graph_free(&graph);
av_buffer_unref(&vk_hw_device_ctx);
return ret;
}
@@ -100,6 +103,7 @@ int init_libplacebo(
if (!libplacebo_filter) {
logger()->error("Filter 'libplacebo' not found.");
avfilter_graph_free(&graph);
av_buffer_unref(&vk_hw_device_ctx);
return AVERROR_FILTER_NOT_FOUND;
}
@@ -123,6 +127,7 @@ int init_libplacebo(
if (ret < 0) {
logger()->error("Cannot create libplacebo filter.");
avfilter_graph_free(&graph);
av_buffer_unref(&vk_hw_device_ctx);
return ret;
}

View File

@@ -109,7 +109,7 @@ void LoggerManager::hook_ffmpeg_logging() {
}
void LoggerManager::unhook_ffmpeg_logging() {
av_log_set_callback(nullptr);
av_log_set_callback(av_log_default_callback);
}
} // namespace logger_manager