From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>,
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/3] gdb: make macro_expand_next return a gdb::unique_xmalloc_ptr<char>
Date: Tue, 30 Jun 2020 18:26:52 -0400 [thread overview]
Message-ID: <ff95ee21-92a2-3a9a-cada-721c4ba89d31@polymtl.ca> (raw)
In-Reply-To: <87v9j88edi.fsf@tromey.com>
On 2020-06-30 4:53 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Simon> I removed the ATTRIBUTE_UNUSED_RESULT on macro_buffer::release, I don't
> Simon> really understand why it's there. I don't see how this method could be
> Simon> called without using the result, that would be an obvious memory leak.
> Simon> The commit that introduced it (4e4a8b932b7 "Add ATTRIBUTE_UNUSED_RESULT
> Simon> to macro_buffer") doesn't give any details.
>
> Sorry about the lack of details!
>
> Simon> - /* Release the text of the buffer to the caller, which is now
> Simon> - responsible for freeing it. */
> Simon> - ATTRIBUTE_UNUSED_RESULT char *release ()
> Simon> + /* Release the text of the buffer to the caller. */
> Simon> + gdb::unique_xmalloc_ptr<char> release ()
>
> In the old code, the caller had to remember to free the resulting char*.
> ATTRIBUTE_UNUSED_RESULT meant that one couldn't write "x.release();"
> without at least doing something with the result.
>
> There was at least one case of this happening, though I didn't read
> through the thread to find out exactly where it was:
>
> https://sourceware.org/pipermail/gdb-patches/2019-February/155835.html
>
> Using a unique pointer eliminates this common source of bugs, so I think
> removing the attribute makes sense.
>
> This patch looks fine to me.
>
> Tom
>
Ok thanks, that makes sense!
Simon
next prev parent reply other threads:[~2020-06-30 22:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-28 16:56 [PATCH 0/3] Small cleanups in macro code Simon Marchi
2020-06-28 16:56 ` [PATCH 1/3] gdb: remove callback in macro expand functions Simon Marchi
2020-06-30 20:47 ` Tom Tromey
2020-06-30 22:14 ` Matt Rice
2020-06-30 22:26 ` Simon Marchi
2020-06-28 16:56 ` [PATCH 2/3] gdb: make macro_expand_next return a gdb::unique_xmalloc_ptr<char> Simon Marchi
2020-06-30 20:53 ` Tom Tromey
2020-06-30 22:26 ` Simon Marchi [this message]
2020-06-28 16:56 ` [PATCH 3/3] gdb: make macro_stringify " Simon Marchi
2020-06-30 20:55 ` Tom Tromey
2020-07-01 0:26 ` Simon Marchi
2020-07-01 15:36 ` Tom Tromey
2020-07-04 2:28 ` Simon Marchi
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=ff95ee21-92a2-3a9a-cada-721c4ba89d31@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.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