On Tue, 22 May 2012, Jordi Ortiz wrote:
>>> - 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?
No, that would be
av_free(buf->data_stack[i--]);
--i decrements i first and uses that value.
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel