This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [rfc] Prompt memory management/cleanups
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org, pmuldoon at redhat dot com
- Date: Wed, 20 Jul 2011 15:14:46 +0100
- Subject: Re: [rfc] Prompt memory management/cleanups
- References: <m3zkk9w1a0.fsf@redhat.com>
On Wednesday 20 July 2011 14:05:11, Phil Muldoon wrote:
> +set_prompt (const char *s, int level)
> {
> -/* ??rehrauer: I don't know why this fails, since it looks as though
> - assignments to prompt are wrapped in calls to xstrdup...
> - if (prompt != NULL)
> - xfree (prompt);
> - */
> - PROMPT (0) = xstrdup (s);
> + /* If S is NULL, just free the PROMPT at level LEVEL and set to
> + NULL. */
> + if (s == NULL)
> + {
> + xfree (PROMPT (level));
> + PROMPT (level) = NULL;
> + }
> + else
> + /* If S == PROMPT then do not free it or set it. If we did
> + that, S (which points to PROMPT), would become garbage. */
> + if (s != PROMPT (level))
> + {
This looks strange, and I suppose complicates the callers' life a bit,
having to know when are they giving up ownership of the string
or not. What would need to change at the callers if we dropped
that s != PROMPT() check?
--
Pedro Alves