PR25993, read of freed memory
Pedro Alves
palves@redhat.com
Tue May 19 19:37:21 GMT 2020
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";
> And then:
>
> bfd_set_filename (nbfd, name->c_str ());
Thanks,
Pedro Alves
More information about the Gdb-patches
mailing list