swscale/graph: fix memleak of cascaded graphs

Just free them directly and discard the parent context.

Fixes: bf738412e8
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
pull/391/head
Niklas Haas 1 month ago
parent 40302cc35b
commit 79452d382f
  1. 12
      libswscale/graph.c

@ -292,7 +292,7 @@ static void legacy_chr_pos(SwsGraph *graph, int *chr_pos, int override, int *war
*chr_pos = override; *chr_pos = override;
} }
static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, int cascaded, static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws,
SwsPass *input, SwsPass **output) SwsPass *input, SwsPass **output)
{ {
SwsInternal *c = sws_internal(sws); SwsInternal *c = sws_internal(sws);
@ -308,11 +308,14 @@ static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, int cascaded,
for (int i = 0; i < num_cascaded; i++) { for (int i = 0; i < num_cascaded; i++) {
SwsContext *sub = c->cascaded_context[i]; SwsContext *sub = c->cascaded_context[i];
const int is_last = i + 1 == num_cascaded; const int is_last = i + 1 == num_cascaded;
ret = init_legacy_subpass(graph, sub, 1, input, is_last ? output : &input); ret = init_legacy_subpass(graph, sub, input, is_last ? output : &input);
if (ret < 0) if (ret < 0)
return ret; return ret;
/* Steal cascaded context, so we can free the parent */
c->cascaded_context[i] = NULL;
} }
sws_free_context(&sws);
return 0; return 0;
} }
@ -336,8 +339,7 @@ static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, int cascaded,
if (!pass) if (!pass)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pass->setup = setup_legacy_swscale; pass->setup = setup_legacy_swscale;
if (!cascaded) /* parent context frees this automatically */ pass->free = free_legacy_swscale;
pass->free = free_legacy_swscale;
/** /**
* For slice threading, we need to create sub contexts, similar to how * For slice threading, we need to create sub contexts, similar to how
@ -452,7 +454,7 @@ static int add_legacy_sws_pass(SwsGraph *graph, SwsFormat src, SwsFormat dst,
brightness, contrast, saturation); brightness, contrast, saturation);
} }
ret = init_legacy_subpass(graph, sws, 0, input, output); ret = init_legacy_subpass(graph, sws, input, output);
if (ret < 0) { if (ret < 0) {
sws_free_context(&sws); sws_free_context(&sws);
return ret; return ret;

Loading…
Cancel
Save