* source.c (symtab_to_fullname): Test 'r >= 0'.

(psymtab_to_fullname): Likewise.
	(get_filename_and_charpos): Make a cleanup.
	(forward_search_command): Likewise.
	(reverse_search_command): Likewise.
	* exec.c (exec_file_attach): Close scratch_chan on failure.
	* nto-procfs.c (procfs_open): Make a cleanup.
	(procfs_pidlist): Likewise.
	(do_closedir_cleanup): New function.
This commit is contained in:
Tom Tromey
2008-10-30 18:42:28 +00:00
parent c22261528c
commit 9fe4a2165d
4 changed files with 58 additions and 37 deletions

View File

@ -1064,7 +1064,7 @@ symtab_to_fullname (struct symtab *s)
r = find_and_open_source (s->objfile, s->filename, s->dirname,
&s->fullname);
if (r)
if (r >= 0)
{
close (r);
return s->fullname;
@ -1093,7 +1093,7 @@ psymtab_to_fullname (struct partial_symtab *ps)
r = find_and_open_source (ps->objfile, ps->filename, ps->dirname,
&ps->fullname);
if (r)
if (r >= 0)
{
close (r);
return ps->fullname;
@ -1251,6 +1251,7 @@ static int
get_filename_and_charpos (struct symtab *s, char **fullname)
{
int desc, linenums_changed = 0;
struct cleanup *cleanups;
desc = open_source_file (s);
if (desc < 0)
@ -1259,13 +1260,14 @@ get_filename_and_charpos (struct symtab *s, char **fullname)
*fullname = NULL;
return 0;
}
cleanups = make_cleanup_close (desc);
if (fullname)
*fullname = s->fullname;
if (s->line_charpos == 0)
linenums_changed = 1;
if (linenums_changed)
find_source_lines (s, desc);
close (desc);
do_cleanups (cleanups);
return linenums_changed;
}
@ -1540,6 +1542,7 @@ forward_search_command (char *regex, int from_tty)
FILE *stream;
int line;
char *msg;
struct cleanup *cleanups;
line = last_line_listed + 1;
@ -1553,24 +1556,21 @@ forward_search_command (char *regex, int from_tty)
desc = open_source_file (current_source_symtab);
if (desc < 0)
perror_with_name (current_source_symtab->filename);
cleanups = make_cleanup_close (desc);
if (current_source_symtab->line_charpos == 0)
find_source_lines (current_source_symtab, desc);
if (line < 1 || line > current_source_symtab->nlines)
{
close (desc);
error (_("Expression not found"));
}
error (_("Expression not found"));
if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
{
close (desc);
perror_with_name (current_source_symtab->filename);
}
perror_with_name (current_source_symtab->filename);
discard_cleanups (cleanups);
stream = fdopen (desc, FDOPEN_MODE);
clearerr (stream);
cleanups = make_cleanup_fclose (stream);
while (1)
{
static char *buf = NULL;
@ -1622,7 +1622,7 @@ forward_search_command (char *regex, int from_tty)
}
printf_filtered (_("Expression not found\n"));
fclose (stream);
do_cleanups (cleanups);
}
static void
@ -1633,6 +1633,7 @@ reverse_search_command (char *regex, int from_tty)
FILE *stream;
int line;
char *msg;
struct cleanup *cleanups;
line = last_line_listed - 1;
@ -1646,24 +1647,21 @@ reverse_search_command (char *regex, int from_tty)
desc = open_source_file (current_source_symtab);
if (desc < 0)
perror_with_name (current_source_symtab->filename);
cleanups = make_cleanup_close (desc);
if (current_source_symtab->line_charpos == 0)
find_source_lines (current_source_symtab, desc);
if (line < 1 || line > current_source_symtab->nlines)
{
close (desc);
error (_("Expression not found"));
}
error (_("Expression not found"));
if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
{
close (desc);
perror_with_name (current_source_symtab->filename);
}
perror_with_name (current_source_symtab->filename);
discard_cleanups (cleanups);
stream = fdopen (desc, FDOPEN_MODE);
clearerr (stream);
cleanups = make_cleanup_fclose (stream);
while (line > 1)
{
/* FIXME!!! We walk right off the end of buf if we get a long line!!! */
@ -1709,7 +1707,7 @@ reverse_search_command (char *regex, int from_tty)
}
printf_filtered (_("Expression not found\n"));
fclose (stream);
do_cleanups (cleanups);
return;
}