Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: msnyder@sonic.net
To: gdb-patches@sourceware.org
Subject: [patch] unfreed memory in cli_command_loop
Date: Fri, 29 Jun 2007 02:17:00 -0000	[thread overview]
Message-ID: <18552.12.7.175.2.1183082732.squirrel@webmail.sonic.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 139 bytes --]

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.


[-- Attachment #2: event-top.txt --]
[-- Type: text/plain, Size: 2069 bytes --]

2007-06-28  Michael Snyder  <msnyder@access-company.com>

	* 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));

             reply	other threads:[~2007-06-29  2:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-29  2:17 msnyder [this message]
2007-07-01 15:39 ` Daniel Jacobowitz
2007-07-01 15:50   ` Michael Snyder
2007-07-03  1:56   ` msnyder

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=18552.12.7.175.2.1183082732.squirrel@webmail.sonic.net \
    --to=msnyder@sonic.net \
    --cc=gdb-patches@sourceware.org \
    /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