Commit af936f95 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

picture_pool_NewFromFormat: improve error handling

parent fb2ff257
...@@ -189,13 +189,15 @@ picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab) ...@@ -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, picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
unsigned count) 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); picture[i] = picture_NewFromFormat(fmt);
if (!picture[i]) if (picture[i] == NULL)
goto error; goto error;
} }
picture_pool_t *pool = picture_pool_New(count, picture); picture_pool_t *pool = picture_pool_New(count, picture);
if (!pool) if (!pool)
goto error; goto error;
...@@ -203,11 +205,8 @@ picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt, ...@@ -203,11 +205,8 @@ picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
return pool; return pool;
error: error:
for (unsigned i = 0; i < count; i++) { while (i > 0)
if (!picture[i]) picture_Release(picture[--i]);
break;
picture_Release(picture[i]);
}
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment