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: [rfc] Prompt memory management/cleanups


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


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