aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-10-30 18:42:28 +0000
committerTom Tromey <tromey@redhat.com>2008-10-30 18:42:28 +0000
commit9fe4a2165de29f0802f0f9eb4801875e0f15c40a (patch)
tree57e0cbb83e955478f8ef776fdf63e64be3c4fc84 /gdb/source.c
parent * infcmd.c (construct_inferior_arguments): Handle newlines (diff)
downloadbinutils-gdb-9fe4a2165de29f0802f0f9eb4801875e0f15c40a.tar.gz
binutils-gdb-9fe4a2165de29f0802f0f9eb4801875e0f15c40a.tar.bz2
binutils-gdb-9fe4a2165de29f0802f0f9eb4801875e0f15c40a.zip
* 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.
Diffstat (limited to 'gdb/source.c')
-rw-r--r--gdb/source.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/gdb/source.c b/gdb/source.c
index 3ef557c6690..c41c193039c 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -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;
}