summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Snyder <msnyder@specifix.com>2007-08-18 00:17:08 +0000
committerMichael Snyder <msnyder@specifix.com>2007-08-18 00:17:08 +0000
commitd5270e6a4199228745adfbb52dcd150a92966d6b (patch)
tree621664f928b982622fa042a51ca3c9288b1deea0
parent2a0bb3591a372e7a056711e087065faf3885b54e (diff)
downloadgdb-d5270e6a4199228745adfbb52dcd150a92966d6b.tar.gz
2007-08-17 Michael Snyder <msnyder@access-company.com>
* completer.c (filename_completer): Avoid memory leak. Remove unnecessary nested block.
-rw-r--r--gdb/ChangeLog3
-rw-r--r--gdb/completer.c52
2 files changed, 29 insertions, 26 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0bd7c85a535..29c8cc303ac 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,8 @@
2007-08-17 Michael Snyder <msnyder@access-company.com>
+ * completer.c (filename_completer): Avoid memory leak.
+ Remove unnecessary nested block.
+
* c-exp.y (parse_number): Memory leak.
* completer.c (location_completer): Must free 'fn_list', except
diff --git a/gdb/completer.c b/gdb/completer.c
index 0a0d30e9bc9..7d3ead9f391 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