[RFA] PR gdb/17210 - fix possible memory leak in read_memory_robust

Pedro Alves palves@redhat.com
Tue Jun 28 17:48:00 GMT 2016


On 06/28/2016 11:42 AM, Yao Qi wrote:
> On Thu, Jun 9, 2016 at 5:33 PM, Tom Tromey <tom@tromey.com> wrote:
>>
>>  VEC(memory_read_result_s) *
>> @@ -1810,6 +1810,8 @@ read_memory_robust (struct target_ops *ops,
>>  {
>>    VEC(memory_read_result_s) *result = 0;
>>    int unit_size = gdbarch_addressable_memory_unit_size (target_gdbarch ());
>> +  struct cleanup *cleanup = make_cleanup (free_memory_read_result_vector,
>> +                                         &result);
>>
> 
> result is a local variable on stack, so its address is meaningless when the
> exception is throw, because the stack has already been destroyed.

Can you clarify?
Cleanups do run before the stack is destroyed.  See most 
free_current_contents users.

Thanks,
Pedro Alves



More information about the Gdb-patches mailing list