From: Simon Marchi <simark@simark.ca>
To: Wei-min Pan <weimin.pan@oracle.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2] gdb: CTF support
Date: Thu, 03 Oct 2019 18:31:00 -0000 [thread overview]
Message-ID: <93caabd4-f25d-61e3-a11d-52bcd8fbe3b6@simark.ca> (raw)
In-Reply-To: <d2c5f8f5-f39c-4b08-5970-c50f8eda683f@oracle.com>
On 2019-10-03 2:21 p.m., Wei-min Pan wrote:
>
> 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
Yes, the second snippet frees the copy returned by ctf_type_aname_raw.
It might just be that you are not familiar with the concept of std::unique_ptr in C++:
https://en.cppreference.com/w/cpp/memory/unique_ptr
It's a wrapper around a simple pointer that automatically calls a deleter function
when it goes out of scope. gdb::unique_xmalloc_ptr is a specialization of std::unique_ptr
that uses xfree as the deleter function.
Here's a similar use:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/fbsd-tdep.c;h=9422e3c1a7e1a65c76b088f42bb5986bd13a089f;hb=HEAD#l1530
`fbsd_core_vnode_path` return a pointer to an allocated C String, which `cwd` wraps. When
it goes out of scope, `cwd` automatically calls `xfree` with the pointer.
Simon
next prev parent reply other threads:[~2019-10-03 18:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 23:45 Weimin Pan
2019-09-21 22:21 ` Simon Marchi
2019-09-23 21:11 ` Weimin Pan
2019-09-24 3:10 ` Simon Marchi
2019-09-25 0:22 ` Weimin Pan
2019-09-25 0:27 ` Simon Marchi
2019-09-25 2:04 ` Wei-min Pan
2019-09-25 2:35 ` Simon Marchi
2019-09-25 21:09 ` Wei-min Pan
2019-09-30 3:06 ` Simon Marchi
2019-10-01 0:37 ` Weimin Pan
2019-10-02 2:47 ` Simon Marchi
2019-10-02 23:10 ` Wei-min Pan
2019-10-03 12:40 ` Simon Marchi
2019-10-03 17:59 ` Wei-min Pan
2019-10-03 18:01 ` Simon Marchi
2019-10-03 18:21 ` Wei-min Pan
2019-10-03 18:31 ` Simon Marchi [this message]
2019-10-03 18:53 ` Wei-min Pan
2019-10-03 20:33 ` Wei-min Pan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93caabd4-f25d-61e3-a11d-52bcd8fbe3b6@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=weimin.pan@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox