This is the mail archive of the gdb-patches@sources.redhat.com 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]

[PATCH 2 of 2] readline rl_prompt corruption fix


This patch needs to be applied to prevent a memory leak in
event-top.c (cli_command_loop) after readline is patched to store prompt
string (see '[PATCH 1 of 2]').

The readline rl_prompt corruption occurs when event-top.c
(display_a_gdb_prompt) passed to readline a prompt string allocated by
alloca ().  This problem affects the HP TUI mode at the moment (when a
user does a up / down / left / right arrow key entry the resulting
cursor position was randomly placed instead of immediately after the gdb
prompt).  Instead of passing malloc'd string to readline, the fix is to
have readline save a copy of the prompt string, otherwise (by mallocing
in gdb) it will be difficult to prevent memory leak.

- Jimmy Guo, guo@cup.hp.com


Fri Jul 28 10:08:31	Jimmy Guo	<guo@cup.hp.com>

	* event-top.c (cli_command_loop): Use temporary storage
	for a_prompt before passing to readline.  Remove usage of
	length.
	(display_a_gdb_prompt): Remove usage of prompt_length.

Index: event-top.c
/usr/local/bin/diff -c -w -L event-top.c event-top.c@@/main/cygnus/21 event-top.c
*** event-top.c
--- event-top.c	Fri Jul 28 10:08:02 2000
***************
*** 171,177 ****
  void
  cli_command_loop (void)
  {
-   int length;
    char *a_prompt;
    char *gdb_prompt = get_prompt ();
  
--- 171,176 ----
***************
*** 182,189 ****
        /* 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));
--- 181,189 ----
        /* 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. */
!       a_prompt = (char *) alloca (strlen (PREFIX (0)) +
! 				  strlen (gdb_prompt) +
! 				  strlen (SUFFIX (0)) + 1);
        strcpy (a_prompt, PREFIX (0));
        strcat (a_prompt, gdb_prompt);
        strcat (a_prompt, SUFFIX (0));
***************
*** 243,249 ****
  void
  display_gdb_prompt (char *new_prompt)
  {
-   int prompt_length = 0;
    char *gdb_prompt = get_prompt ();
  
  #ifdef UI_OUT
--- 243,248 ----
***************
*** 277,293 ****
    if (!new_prompt)
      {
        /* Just use the top of the prompt stack. */
!       prompt_length = strlen (PREFIX (0)) +
! 	strlen (SUFFIX (0)) +
! 	strlen (gdb_prompt) + 1;
! 
!       new_prompt = (char *) alloca (prompt_length);
! 
!       /* Prefix needs to have new line at end. */
        strcpy (new_prompt, PREFIX (0));
        strcat (new_prompt, gdb_prompt);
-       /* Suffix needs to have a new line at end and \032 \032 at
-          beginning. */
        strcat (new_prompt, SUFFIX (0));
      }
  
--- 276,286 ----
    if (!new_prompt)
      {
        /* Just use the top of the prompt stack. */
!       new_prompt = (char *) alloca (strlen (PREFIX (0)) +
! 				    strlen (gdb_prompt) +
! 				    strlen (SUFFIX (0)) + 1);
        strcpy (new_prompt, PREFIX (0));
        strcat (new_prompt, gdb_prompt);
        strcat (new_prompt, SUFFIX (0));
      }
  


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