2007-08-17 Michael Snyder <msnyder@access-company.com>

* completer.c (filename_completer): Avoid memory leak.
	Remove unnecessary nested block.
This commit is contained in:
Michael Snyder 2007-08-18 00:17:08 +00:00
parent 67f5fb248e
commit 1e8189fbb5
2 changed files with 29 additions and 26 deletions

View file

@ -1,5 +1,8 @@
2007-08-17 Michael Snyder <msnyder@access-company.com> 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. * c-exp.y (parse_number): Memory leak.
* completer.c (location_completer): Must free 'fn_list', except * completer.c (location_completer): Must free 'fn_list', except

View file

@ -129,7 +129,7 @@ filename_completer (char *text, char *word)
subsequent_name = 0; subsequent_name = 0;
while (1) while (1)
{ {
char *p; char *p, *q;
p = rl_filename_completion_function (text, subsequent_name); p = rl_filename_completion_function (text, subsequent_name);
if (return_val_used >= return_val_alloced) 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 /* Like emacs, don't complete on old versions. Especially useful
in the "source" command. */ in the "source" command. */
if (p[strlen (p) - 1] == '~') if (p[strlen (p) - 1] == '~')
continue; {
xfree (p);
continue;
}
{ if (word == text)
char *q; /* Return exactly p. */
if (word == text) return_val[return_val_used++] = p;
/* Return exactly p. */ else if (word > text)
return_val[return_val_used++] = p; {
else if (word > text) /* Return some portion of p. */
{ q = xmalloc (strlen (p) + 5);
/* Return some portion of p. */ strcpy (q, p + (word - text));
q = xmalloc (strlen (p) + 5); return_val[return_val_used++] = q;
strcpy (q, p + (word - text)); xfree (p);
return_val[return_val_used++] = q; }
xfree (p); else
} {
else /* Return some of TEXT plus p. */
{ q = xmalloc (strlen (p) + (text - word) + 5);
/* Return some of TEXT plus p. */ strncpy (q, word, text - word);
q = xmalloc (strlen (p) + (text - word) + 5); q[text - word] = '\0';
strncpy (q, word, text - word); strcat (q, p);
q[text - word] = '\0'; return_val[return_val_used++] = q;
strcat (q, p); xfree (p);
return_val[return_val_used++] = q; }
xfree (p);
}
}
} }
#if 0 #if 0
/* There is no way to do this just long enough to affect quote inserting /* There is no way to do this just long enough to affect quote inserting