[Mesa-dev] [PATCH] r600/sb: Fix memory leak

Bartosz Tomczyk bartosz.tomczyk86 at gmail.com
Mon Jan 30 14:31:28 UTC 2017


It did not change anything, as we are not dereferencing iterator after
delete.

I think changing:
delete *it;
uses.erase(it);

to:
use_info *ptr = *it;
uses.erase(it);
delete ptr;

don't make it more readable or safer, but I can change it if you want to.

On Mon, Jan 30, 2017 at 3:16 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:

> Nice find!
>
> On 29.01.2017 19:10, Bartosz Tomczyk wrote:
>
>> ---
>>  src/gallium/drivers/r600/sb/sb_valtable.cpp | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gallium/drivers/r600/sb/sb_valtable.cpp
>> b/src/gallium/drivers/r600/sb/sb_valtable.cpp
>> index a8b7b49cd4..d31a1b76d5 100644
>> --- a/src/gallium/drivers/r600/sb/sb_valtable.cpp
>> +++ b/src/gallium/drivers/r600/sb/sb_valtable.cpp
>> @@ -241,6 +241,7 @@ void value::remove_use(const node *n) {
>>         {
>>                 // TODO assert((*it)->kind == kind) ?
>>                 // TODO assert((*it)->arg == arg) ?
>> +               delete *it;
>>                 uses.erase(it);
>>
>
> The delete should really be after the erase.
>
> Cheers,
> Nicolai
>
>
>         }
>>  }
>> @@ -290,7 +291,12 @@ bool value::is_prealloc() {
>>  }
>>
>>  void value::delete_uses() {
>> -       uses.erase(uses.begin(), uses.end());
>> +       for (uselist::iterator it = uses.begin(); it != uses.end(); ++it)
>> +       {
>> +               delete *it;
>> +       }
>> +
>> +       uses.clear();
>>  }
>>
>>  void ra_constraint::update_values() {
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170130/7d4a52d3/attachment-0001.html>


More information about the mesa-dev mailing list