diff mbox series

[FFmpeg-devel,1/4] avcodec/hevcdec: Combine multiple allocations

Message ID AM7PR03MB6660B14C8ABBE0144FDFFB898F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/hevcdec: Combine multiple allocations | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 5, 2022, 9:18 p.m. UTC
Reduces the number of allocs and frees.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/hevcdec.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Michael Niedermayer Jan. 6, 2022, 9:40 a.m. UTC | #1
On Wed, Jan 05, 2022 at 10:18:11PM +0100, Andreas Rheinhardt wrote:
> Reduces the number of allocs and frees.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/hevcdec.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)

something in the patches today causes a segfault in a hevc stream with slice threading
iam trying to bisect it but it but it does not replicate at all reliably ATM
so i dont even know if its from a patch today
just wanted to report what i know ATM ...

thx


[...]
Andreas Rheinhardt Jan. 6, 2022, 9:56 a.m. UTC | #2
Michael Niedermayer:
> On Wed, Jan 05, 2022 at 10:18:11PM +0100, Andreas Rheinhardt wrote:
>> Reduces the number of allocs and frees.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/hevcdec.c | 11 ++++-------
>>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> something in the patches today causes a segfault in a hevc stream with slice threading
> iam trying to bisect it but it but it does not replicate at all reliably ATM
> so i dont even know if its from a patch today
> just wanted to report what i know ATM ...
> 
> thx

On what arch did you test this? Josh's recent patchset [1] caused
segfaults on aarch64, see also [2]. I actually tested with slice
threading (which this data is all about). But I will nevertheless look
at your sample.

- Andreas

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2022-January/290774.html
[2]: https://ffmpeg.org/pipermail/ffmpeg-devel/2022-January/290862.html
Michael Niedermayer Jan. 6, 2022, noon UTC | #3
On Thu, Jan 06, 2022 at 10:56:37AM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Jan 05, 2022 at 10:18:11PM +0100, Andreas Rheinhardt wrote:
> >> Reduces the number of allocs and frees.
> >>
> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> >> ---
> >>  libavcodec/hevcdec.c | 11 ++++-------
> >>  1 file changed, 4 insertions(+), 7 deletions(-)
> > 
> > something in the patches today causes a segfault in a hevc stream with slice threading
> > iam trying to bisect it but it but it does not replicate at all reliably ATM
> > so i dont even know if its from a patch today
> > just wanted to report what i know ATM ...
> > 
> > thx
> 
> On what arch did you test this? Josh's recent patchset [1] caused
> segfaults on aarch64, see also [2]. I actually tested with slice
> threading (which this data is all about). But I will nevertheless look
> at your sample.

x86-64 

[...]
diff mbox series

Patch

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 8d7a4f7147..568bdb5ab7 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2621,17 +2621,15 @@  static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
     const uint8_t *data = nal->data;
     int length          = nal->size;
     HEVCLocalContext *lc = s->HEVClc;
-    int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
-    int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
+    int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, 2 * sizeof(int));
+    int *arg;
     int64_t offset;
     int64_t startheader, cmpt = 0;
     int i, j, res = 0;
 
-    if (!ret || !arg) {
-        av_free(ret);
-        av_free(arg);
+    if (!ret)
         return AVERROR(ENOMEM);
-    }
+    arg = ret + s->sh.num_entry_point_offsets + 1;
 
     if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * s->ps.sps->ctb_width >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
         av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
@@ -2716,7 +2714,6 @@  static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
         res += ret[i];
 error:
     av_free(ret);
-    av_free(arg);
     return res;
 }