[FFmpeg-devel] [PATCH 2/2] avformat/avc, mxfenc: Avoid allocation of H264 SPS structure, fix memleak
Tomas Härdin
tjoppen at acc.umu.se
Fri Jun 26 12:27:54 EEST 2020
ons 2020-06-24 klockan 19:15 +0200 skrev Andreas Rheinhardt:
> Up until now, ff_avc_decode_sps would parse a SPS and return some
> properties from it in a freshly allocated structure. Yet said
> structure
> is very small and completely internal to libavformat, so there is no
> reason to use the heap for it. This commit therefore changes the
> function to return an int and to modify a caller-provided structure.
> This will also allow ff_avc_decode_sps to return better error codes
> in
> the future.
>
> It also fixes a memleak in mxfenc: If a packet contained multiple
> SPS,
> only the SPS structure belonging to the last SPS would be freed, the
> other ones would leak when the pointer is overwritten to point to the
> new SPS structure. Of course, without allocations there are no leaks.
> This is Coverity issue #1445194.
>
> Furthermore, the SPS structure has been renamed from
> H264SequenceParameterSet to H264SPS in order to avoid overlong lines.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> This commit only intends to fix the memleak in mxfenc; I leave any
> modifications that might need to be made for the case of several SPS
> to
> other people.
>
> Apropos better error codes: Error checking will necessitate
> modifications
> to the helper functions; i.e. get_ue_golomb does not allow to check
> for
> invalid data (e.g. 32 zero bits in a row). I am surprised that the
> fuzzer hasn't complained about this yet.
>
> libavformat/avc.c | 27 ++++++++++++---------------
> libavformat/avc.h | 4 ++--
> libavformat/mxfenc.c | 15 +++++++--------
> 3 files changed, 21 insertions(+), 25 deletions(-)
Looks OK to me. Fewer allocations are generally better
/Tomas
More information about the ffmpeg-devel
mailing list