diff mbox series

[FFmpeg-devel,3/5] avfilter/signature_lookup: Allocate buffers jointly

Message ID AS8P250MB0744AB0DBB84A56A5BC880ED8F4E2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit bf82b6517e5357c9ac4f2e3fbc9d017f95575ab6
Headers show
Series [FFmpeg-devel,1/5] avfilter/vf_signature: Allocate arrays together | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 14, 2024, 12:05 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/signature_lookup.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c
index 90b1d0eadf..3a42737e1a 100644
--- a/libavfilter/signature_lookup.c
+++ b/libavfilter/signature_lookup.c
@@ -205,15 +205,17 @@  static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont
     } hspace_elem;
 
     /* houghspace */
-    hspace_elem **hspace = av_mallocz(MAX_FRAMERATE * sizeof(*hspace));
+    hspace_elem **hspace = av_malloc(MAX_FRAMERATE * sizeof(*hspace));
+    hspace_elem *hspaces;
 
     if (!hspace)
         return NULL;
     /* initialize houghspace */
+    hspaces = av_malloc((2 * HOUGH_MAX_OFFSET + 1) * sizeof(*hspaces) * MAX_FRAMERATE);
+    if (!hspaces)
+        goto error;
     for (i = 0; i < MAX_FRAMERATE; i++) {
-        hspace[i] = av_malloc_array(2 * HOUGH_MAX_OFFSET + 1, sizeof(hspace_elem));
-        if (!hspace[i])
-            goto error;
+        hspace[i] = hspaces + i * (2 * HOUGH_MAX_OFFSET + 1);
         for (j = 0; j < 2 * HOUGH_MAX_OFFSET + 1; j++) {
             hspace[i][j].score = 0;
             hspace[i][j].dist = 99999;
@@ -325,10 +327,8 @@  static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont
         }
     }
     error:
-    for (i = 0; i < MAX_FRAMERATE; i++) {
-        av_freep(&hspace[i]);
-    }
     av_freep(&hspace);
+    av_free(hspaces);
     return cands;
 }