[vlc-devel] [PATCH 06/12] picture_pool: Don't use VLAs

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Dec 8 15:19:10 CET 2020


---
 src/misc/picture_pool.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index d2df4bf2eb..7ebaf00eaa 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -128,7 +128,9 @@ picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab)
 picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
                                            unsigned count)
 {
-    picture_t *picture[count ? count : 1];
+    picture_t **picture = malloc(sizeof(*picture) * (count ? count : 1));
+    if (picture == NULL)
+        return NULL;
     unsigned i;
 
     for (i = 0; i < count; i++) {
@@ -141,17 +143,21 @@ picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
     if (!pool)
         goto error;
 
+    free(picture);
     return pool;
 
 error:
     while (i > 0)
         picture_Release(picture[--i]);
+    free(picture);
     return NULL;
 }
 
 picture_pool_t *picture_pool_Reserve(picture_pool_t *master, unsigned count)
 {
-    picture_t *picture[count ? count : 1];
+    picture_t** picture = malloc(sizeof(*picture) * (count ? count : 1));
+    if (picture == NULL)
+        return NULL;
     unsigned i;
 
     for (i = 0; i < count; i++) {
@@ -164,11 +170,13 @@ picture_pool_t *picture_pool_Reserve(picture_pool_t *master, unsigned count)
     if (!pool)
         goto error;
 
+    free(picture);
     return pool;
 
 error:
     while (i > 0)
         picture_Release(picture[--i]);
+    free(picture);
     return NULL;
 }
 
-- 
2.29.2



More information about the vlc-devel mailing list