swscale: clean up allocated frames on error

Matches the semantics of sws_frame_begin(), which also cleans up any
allocated buffers on error.

This is an issue introduced by the commit that allowed ff_sws_graph_run()
to fail in the first place.

Fixes: 563cc8216b
This commit is contained in:
Niklas Haas
2026-03-25 11:14:06 +01:00
parent 6c89a30ecd
commit 2deca0ec19

View File

@@ -1366,7 +1366,7 @@ static int frame_ref(AVFrame *dst, const AVFrame *src)
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
{
int ret;
int ret, allocated = 0;
SwsInternal *c = sws_internal(sws);
if (!src || !dst)
return AVERROR(EINVAL);
@@ -1411,12 +1411,16 @@ int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
ret = frame_alloc_buffers(sws, dst);
if (ret < 0)
return ret;
allocated = 1;
process_frame:
for (int field = 0; field < (bot ? 2 : 1); field++) {
ret = ff_sws_graph_run(c->graph[field], dst, src);
if (ret < 0)
if (ret < 0) {
if (allocated)
av_frame_unref(dst);
return ret;
}
}
return 0;