PR25993, read of freed memory
Simon Marchi
simark@simark.ca
Tue May 19 19:38:57 GMT 2020
On 2020-05-19 3:37 p.m., Pedro Alves via Gdb-patches wrote:
> On 5/19/20 2:27 PM, Simon Marchi wrote:
>> It now doesn't really make sense for symbol_file_add_from_memory to accept a malloc-ed
>> string (the point was that before we gave ownership of that malloc-ed string to bfd).
>>
>> Can you please change `char *name` to be `gdb::optional<std::string>`?
>>
>> The caller that passes a name should use string_printf to build the string, as mentioned
>> above. The caller that does not pass a name can pass `{}`, to pass an empty optional.
>
> Wouldn't 'const char * or NULL' work? Seems way simpler to me.
>
>>
>> The `if (name == NULL)` would become something like:
>>
>> if (!name.has_value ())
>> name.emplace ("shared object read from target memory");
>>
>
> This would just be
>
> if (name == NULL)
> name = "shared object read from target memory";
Ah yes that's better. Though the caller should still be changed to use string_printf and
str.c_str ().
Simon
More information about the Gdb-patches
mailing list