]> git.sesse.net Git - ffmpeg/commit
avfilter/vf_overlay: Fix double-free of AVFilterFormats on error
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 7 Aug 2020 12:42:57 +0000 (14:42 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 23 Aug 2020 21:29:58 +0000 (23:29 +0200)
commita86ee5fd79840dc4af3e3f5c90ff8ce19b9ae993
tree150c0e3a416d9385ccb5d9108bac5beb34e84953
parent07240c36c2912cea96dd9d11c8e3ed27995a2b3c
avfilter/vf_overlay: Fix double-free of AVFilterFormats on error

The query_formats function of the overlay filter tries to allocate
two lists (only one in a special case) of formats which on success
are attached to more permanent objects (AVFilterLinks) for storage
afterwards. If attaching a list to an AVFilterLink succeeds, it is
in turn owned by the AVFilterLink (or more exactly, the AVFilterLink
becomes one of the common owners of the list). Yet if attaching a list
to one of its links succeeds and an error happens lateron, both lists
were manually freed, whic is wrong if the list is already owned by one
or more links; these links' pointers to their lists will become dangling
and there will be a double-free/use-after-free when these links are
cleaned up automatically.

This commit fixes this by removing the custom freeing code; this will
temporarily add a leaking codepath (if attaching a list not already
owned by a link to a link fails, the list will leak), but this will
be fixed soon by making sure that an AVFilterFormats without owner will
be automatically freed when attaching it to an AVFilterLink fails.
Notice that at most one list leaks because a new list is only allocated
after the old list has been successfully attached to a link.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavfilter/vf_overlay.c