On Tue, May 22, 2012 at 12:05:40AM +0200, Jordi Ortiz wrote:
>
> --- a/libavcodec/dwt.c
> +++ b/libavcodec/dwt.c
> @@ -33,10 +33,27 @@ void ff_slice_buffer_init(slice_buffer *buf, int
> line_count,
>
> - for (i = 0; i < max_allocated_lines; i++)
> + for (i = 0; i < max_allocated_lines; i++) {
> buf->data_stack[i] = av_malloc(sizeof(IDWTELEM) * line_width);
> + if (!buf->data_stack[i]) {
> + i--;
> + while (i >= 0) {
> + av_free(buf->data_stack[i]);
> + i--;
> + }
> + av_free(buf->data_stack);
> + av_free(buf->line);
> + return AVERROR(ENOMEM);
Much better, but the loop can still be done simpler:
if (!buf->data_stack[i]) {
while (i >= 0) {
i--;
av_free(buf->data_stack[i]);
}
or
if (!buf->data_stack[i]) {
while (i >= 0)
av_free(buf->data_stack[--i]);
or
if (!buf->data_stack[i])
for (i--; i >= 0; i--)
av_free(buf->data_stack[i]);
or
if (!buf->data_stack[i])
for (; i > 0; i--)
av_free(buf->data_stack[i - 1]);
or
if (!buf->data_stack[i])
for (; i > 0;)
av_free(buf->data_stack[--i]);
Bah, I should go do something else now ;)
Choose whichever you prefer - the second and fifth are shortest, the
third keeps the index trickery in one place ...
Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel