From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31134 invoked by alias); 20 Jul 2011 14:15:25 -0000 Received: (qmail 31121 invoked by uid 22791); 20 Jul 2011 14:15:24 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Jul 2011 14:14:51 +0000 Received: (qmail 6143 invoked from network); 20 Jul 2011 14:14:48 -0000 Received: from unknown (HELO scottsdale.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 20 Jul 2011 14:14:48 -0000 From: Pedro Alves To: gdb-patches@sourceware.org, pmuldoon@redhat.com Subject: Re: [rfc] Prompt memory management/cleanups Date: Wed, 20 Jul 2011 14:30:00 -0000 User-Agent: KMail/1.13.6 (Linux/2.6.38-8-generic; KDE/4.6.2; x86_64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201107201514.46833.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00524.txt.bz2 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