From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4438 invoked by alias); 29 Jun 2007 02:05:37 -0000 Received: (qmail 4430 invoked by uid 22791); 29 Jun 2007 02:05:36 -0000 X-Spam-Check-By: sourceware.org Received: from b.mail.sonic.net (HELO b.mail.sonic.net) (64.142.19.5) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 29 Jun 2007 02:05:34 +0000 Received: from webmail.sonic.net (b.webmail.sonic.net [64.142.100.148]) by b.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id l5T25WsF014321 for ; Thu, 28 Jun 2007 19:05:32 -0700 Received: from 12.7.175.2 (SquirrelMail authenticated user msnyder) by webmail.sonic.net with HTTP; Thu, 28 Jun 2007 19:05:32 -0700 (PDT) Message-ID: <18552.12.7.175.2.1183082732.squirrel@webmail.sonic.net> Date: Fri, 29 Jun 2007 02:17:00 -0000 Subject: [patch] unfreed memory in cli_command_loop From: msnyder@sonic.net To: gdb-patches@sourceware.org User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: multipart/mixed;boundary="----=_20070628190532_11719" 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: 2007-06/txt/msg00517.txt.bz2 ------=_20070628190532_11719 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Content-length: 139 Minor memory leak. I checked to make sure that readline makes and keeps its own copy of this string, so it's OK for us to free our copy. ------=_20070628190532_11719 Content-Type: text/plain; name="event-top.txt" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="event-top.txt" Content-length: 2069 2007-06-28 Michael Snyder * event-top.c (cli_command_loop): Prompt string can (and should) be freed after call to readline (Coverity). Also move local var declarations into block where they are used. Index: event-top.c =================================================================== RCS file: /cvs/src/src/gdb/event-top.c,v retrieving revision 1.50 diff -p -r1.50 event-top.c *** event-top.c 9 Feb 2007 23:45:35 -0000 1.50 --- event-top.c 29 Jun 2007 02:00:03 -0000 *************** rl_callback_read_char_wrapper (gdb_clien *** 186,204 **** void cli_command_loop (void) { - int length; - char *a_prompt; - char *gdb_prompt = get_prompt (); - /* If we are using readline, set things up and display the first prompt, otherwise just print the prompt. */ if (async_command_editing_p) { /* Tell readline what the prompt to display is and what function it will need to call after a whole line is read. This also displays the first prompt. */ ! length = strlen (PREFIX (0)) + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1; a_prompt = (char *) xmalloc (length); strcpy (a_prompt, PREFIX (0)); strcat (a_prompt, gdb_prompt); strcat (a_prompt, SUFFIX (0)); --- 186,206 ---- void cli_command_loop (void) { /* If we are using readline, set things up and display the first prompt, otherwise just print the prompt. */ if (async_command_editing_p) { + int length; + char *a_prompt; + char *gdb_prompt = get_prompt (); + /* Tell readline what the prompt to display is and what function it will need to call after a whole line is read. This also displays the first prompt. */ ! length = strlen (PREFIX (0)) ! + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1; a_prompt = (char *) xmalloc (length); + make_cleanup (xfree, a_prompt); strcpy (a_prompt, PREFIX (0)); strcat (a_prompt, gdb_prompt); strcat (a_prompt, SUFFIX (0)); ------=_20070628190532_11719--