[vlc-commits] picture_pool_NewFromFormat: improve error handling

Rémi Denis-Courmont git at videolan.org
Sat Nov 1 10:31:47 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov  1 11:02:00 2014 +0200| [af936f95b5d35e3053103a8046cc520e3d20ca7d] | committer: Rémi Denis-Courmont

picture_pool_NewFromFormat: improve error handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=af936f95b5d35e3053103a8046cc520e3d20ca7d
---

 src/misc/picture_pool.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 14d8f09..3c080b3 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -189,13 +189,15 @@ 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];
+    picture_t *picture[count ? count : 1];
+    unsigned i;
 
-    for (unsigned i = 0; i < count; i++) {
+    for (i = 0; i < count; i++) {
         picture[i] = picture_NewFromFormat(fmt);
-        if (!picture[i])
+        if (picture[i] == NULL)
             goto error;
     }
+
     picture_pool_t *pool = picture_pool_New(count, picture);
     if (!pool)
         goto error;
@@ -203,11 +205,8 @@ picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
     return pool;
 
 error:
-    for (unsigned i = 0; i < count; i++) {
-        if (!picture[i])
-            break;
-        picture_Release(picture[i]);
-    }
+    while (i > 0)
+        picture_Release(picture[--i]);
     return NULL;
 }
 



More information about the vlc-commits mailing list