diff options
author | Michael Snyder <msnyder@vmware.com> | 2007-08-18 00:17:08 +0000 |
---|---|---|
committer | Michael Snyder <msnyder@vmware.com> | 2007-08-18 00:17:08 +0000 |
commit | 1e8189fbb5629e0f78298e420b78b9fd381d6ff4 (patch) | |
tree | a4544ca386216a06c32f3b9577474f54fd6169c1 /gdb/completer.c | |
parent | 67f5fb248edad1005c125682e6151422a7861144 (diff) | |
download | gdb-1e8189fbb5629e0f78298e420b78b9fd381d6ff4.zip gdb-1e8189fbb5629e0f78298e420b78b9fd381d6ff4.tar.gz gdb-1e8189fbb5629e0f78298e420b78b9fd381d6ff4.tar.bz2 |
2007-08-17 Michael Snyder <msnyder@access-company.com>
* completer.c (filename_completer): Avoid memory leak.
Remove unnecessary nested block.
Diffstat (limited to 'gdb/completer.c')
-rw-r--r-- | gdb/completer.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/gdb/completer.c b/gdb/completer.c index 0a0d30e..7d3ead9 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -129,7 +129,7 @@ filename_completer (char *text, char *word) subsequent_name = 0; while (1) { - char *p; + char *p, *q; p = rl_filename_completion_function (text, subsequent_name); if (return_val_used >= return_val_alloced) { @@ -151,32 +151,32 @@ filename_completer (char *text, char *word) /* Like emacs, don't complete on old versions. Especially useful in the "source" command. */ if (p[strlen (p) - 1] == '~') - continue; + { + xfree (p); + continue; + } - { - char *q; - if (word == text) - /* Return exactly p. */ - return_val[return_val_used++] = p; - else if (word > text) - { - /* Return some portion of p. */ - q = xmalloc (strlen (p) + 5); - strcpy (q, p + (word - text)); - return_val[return_val_used++] = q; - xfree (p); - } - else - { - /* Return some of TEXT plus p. */ - q = xmalloc (strlen (p) + (text - word) + 5); - strncpy (q, word, text - word); - q[text - word] = '\0'; - strcat (q, p); - return_val[return_val_used++] = q; - xfree (p); - } - } + if (word == text) + /* Return exactly p. */ + return_val[return_val_used++] = p; + else if (word > text) + { + /* Return some portion of p. */ + q = xmalloc (strlen (p) + 5); + strcpy (q, p + (word - text)); + return_val[return_val_used++] = q; + xfree (p); + } + else + { + /* Return some of TEXT plus p. */ + q = xmalloc (strlen (p) + (text - word) + 5); + strncpy (q, word, text - word); + q[text - word] = '\0'; + strcat (q, p); + return_val[return_val_used++] = q; + xfree (p); + } } #if 0 /* There is no way to do this just long enough to affect quote inserting |