This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] gdb: CTF support


On 10/3/2019 11:01 AM, Simon Marchi wrote:
> On 2019-10-03 1:58 p.m., Wei-min Pan wrote:
>> But the `free` call is needed to free up space allocated by libctf's ctf_type_aname_raw.
>
> That's the point of gdb::unique_xmalloc_pointer: it will automatically call xfree (free) when > on scope exit, free'ing this copy.  It's preferred to use this instead of manually calling > xfree, because it makes it harder to forget to free the memory (or to free it twice).

Let's use an example (checking omitted):

We're replacing:
  name = ctf_type_aname_raw (fp, tid);
  TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name);
  free (name);

with
  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
  TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name.get ());

The allocated copy from ctf_type_aname_raw is not freed. Or did I miss something?

Weimin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]