>>> -    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]);
>
>
> Wouldn't these two try to free data_stack[-1]? The other ones look ok.
>

I think only the first one is bad. The second would update i after access
on i==0 then exit the loop. Right?
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to