avformat/dv: Avoid allocation for reading timecode

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-08-02 00:58:48 +02:00
parent 8b0bba864b
commit 1fbfa42432
1 changed files with 4 additions and 9 deletions

View File

@ -470,19 +470,15 @@ static int dv_read_timecode(AVFormatContext *s) {
int64_t pos = avio_tell(s->pb); int64_t pos = avio_tell(s->pb);
// Read 3 DIF blocks: Header block and 2 Subcode blocks. // Read 3 DIF blocks: Header block and 2 Subcode blocks.
int partial_frame_size = 3 * 80; #define PARTIAL_FRAME_SIZE (3 * 80)
uint8_t *partial_frame = av_mallocz(sizeof(*partial_frame) * uint8_t partial_frame[PARTIAL_FRAME_SIZE];
partial_frame_size);
RawDVContext *c = s->priv_data; RawDVContext *c = s->priv_data;
if (!partial_frame)
return AVERROR(ENOMEM);
ret = avio_read(s->pb, partial_frame, partial_frame_size); ret = avio_read(s->pb, partial_frame, PARTIAL_FRAME_SIZE);
if (ret < 0) if (ret < 0)
goto finish; goto finish;
if (ret < partial_frame_size) { if (ret < PARTIAL_FRAME_SIZE) {
ret = -1; ret = -1;
goto finish; goto finish;
} }
@ -494,7 +490,6 @@ static int dv_read_timecode(AVFormatContext *s) {
av_log(s, AV_LOG_ERROR, "Detected timecode is invalid\n"); av_log(s, AV_LOG_ERROR, "Detected timecode is invalid\n");
finish: finish:
av_free(partial_frame);
avio_seek(s->pb, pos, SEEK_SET); avio_seek(s->pb, pos, SEEK_SET);
return ret; return ret;
} }