diff mbox series

[FFmpeg-devel,2/2] avformat/dv: Avoid allocation for reading timecode

Message ID 20200802114731.901-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 1fbfa42432b1348944829a51997f1a0d8f11c6bc
Headers show
Series [FFmpeg-devel,1/2] avformat/dv: Avoid alloction of DVDemuxContext | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 2, 2020, 11:47 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/dv.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

Comments

Paul B Mahol Aug. 2, 2020, 12:27 p.m. UTC | #1
On 8/2/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/dv.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/libavformat/dv.c b/libavformat/dv.c
> index 9179e6cec6..d25641daac 100644
> --- a/libavformat/dv.c
> +++ b/libavformat/dv.c
> @@ -470,19 +470,15 @@ static int dv_read_timecode(AVFormatContext *s) {
>      int64_t pos = avio_tell(s->pb);
>
>      // Read 3 DIF blocks: Header block and 2 Subcode blocks.
> -    int partial_frame_size = 3 * 80;
> -    uint8_t *partial_frame = av_mallocz(sizeof(*partial_frame) *
> -                                        partial_frame_size);
> -
> +#define PARTIAL_FRAME_SIZE (3 * 80)
> +    uint8_t partial_frame[PARTIAL_FRAME_SIZE];
>      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)
>          goto finish;
>
> -    if (ret < partial_frame_size) {
> +    if (ret < PARTIAL_FRAME_SIZE) {
>          ret = -1;
>          goto finish;
>      }
> @@ -494,7 +490,6 @@ static int dv_read_timecode(AVFormatContext *s) {
>          av_log(s, AV_LOG_ERROR, "Detected timecode is invalid\n");
>
>  finish:
> -    av_free(partial_frame);
>      avio_seek(s->pb, pos, SEEK_SET);
>      return ret;
>  }
> --
> 2.20.1


lgtm
diff mbox series

Patch

diff --git a/libavformat/dv.c b/libavformat/dv.c
index 9179e6cec6..d25641daac 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -470,19 +470,15 @@  static int dv_read_timecode(AVFormatContext *s) {
     int64_t pos = avio_tell(s->pb);
 
     // Read 3 DIF blocks: Header block and 2 Subcode blocks.
-    int partial_frame_size = 3 * 80;
-    uint8_t *partial_frame = av_mallocz(sizeof(*partial_frame) *
-                                        partial_frame_size);
-
+#define PARTIAL_FRAME_SIZE (3 * 80)
+    uint8_t partial_frame[PARTIAL_FRAME_SIZE];
     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)
         goto finish;
 
-    if (ret < partial_frame_size) {
+    if (ret < PARTIAL_FRAME_SIZE) {
         ret = -1;
         goto finish;
     }
@@ -494,7 +490,6 @@  static int dv_read_timecode(AVFormatContext *s) {
         av_log(s, AV_LOG_ERROR, "Detected timecode is invalid\n");
 
 finish:
-    av_free(partial_frame);
     avio_seek(s->pb, pos, SEEK_SET);
     return ret;
 }