Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-06-24 18:51:58 +0300
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-07-01 22:39:54 +0300
commitfd6cb26583700c4ea294ac367dcfe3c777624dca (patch)
tree636d2f276bff15d185ec14c344cc161e38231607 /libavformat/avc.c
parent847bb1d5226af1cbe85bc09527f4cc25389aad7d (diff)
avformat/avc, mxfenc: Avoid allocation of H264 SPS structure, fix memleak
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. Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> (cherry picked from commit a0b6df0a3953e2586e63f513485c4d2d42507d7f) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/avc.c')
-rw-r--r--libavformat/avc.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/libavformat/avc.c b/libavformat/avc.c
index a041e84357..34edec04f0 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -308,27 +308,24 @@ static inline int get_se_golomb(GetBitContext *gb) {
return ((v >> 1) ^ sign) - sign;
}
-H264SequenceParameterSet *ff_avc_decode_sps(const uint8_t *buf, int buf_size)
+int ff_avc_decode_sps(H264SPS *sps, const uint8_t *buf, int buf_size)
{
int i, j, ret, rbsp_size, aspect_ratio_idc, pic_order_cnt_type;
int num_ref_frames_in_pic_order_cnt_cycle;
int delta_scale, lastScale = 8, nextScale = 8;
int sizeOfScalingList;
- H264SequenceParameterSet *sps = NULL;
GetBitContext gb;
uint8_t *rbsp_buf;
rbsp_buf = ff_nal_unit_extract_rbsp(buf, buf_size, &rbsp_size, 0);
if (!rbsp_buf)
- return NULL;
+ return AVERROR(ENOMEM);
ret = init_get_bits8(&gb, rbsp_buf, rbsp_size);
if (ret < 0)
goto end;
- sps = av_mallocz(sizeof(*sps));
- if (!sps)
- goto end;
+ memset(sps, 0, sizeof(*sps));
sps->profile_idc = get_bits(&gb, 8);
sps->constraint_set_flags |= get_bits1(&gb) << 0; // constraint_set0_flag
@@ -423,7 +420,8 @@ H264SequenceParameterSet *ff_avc_decode_sps(const uint8_t *buf, int buf_size)
sps->sar.den = 1;
}
+ ret = 0;
end:
av_free(rbsp_buf);
- return sps;
+ return ret;
}