(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.
+2008-10-28 Tom Tromey <tromey@redhat.com>
+
+ * 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.
+
2008-10-30 Andreas Schwab <schwab@suse.de>
* infcmd.c (construct_inferior_arguments): Handle newlines
scratch_chan);
if (!exec_bfd)
- error (_("\"%s\": could not open as an executable file: %s"),
- scratch_pathname, bfd_errmsg (bfd_get_error ()));
+ {
+ close (scratch_chan);
+ error (_("\"%s\": could not open as an executable file: %s"),
+ scratch_pathname, bfd_errmsg (bfd_get_error ()));
+ }
/* At this point, scratch_pathname and exec_bfd->name both point to the
same malloc'd string. However exec_close() will attempt to free it
char buffer[50];
int fd, total_size;
procfs_sysinfo *sysinfo;
+ struct cleanup *cleanups;
nto_is_nto_target = procfs_is_nto_target;
safe_strerror (errno));
error (_("Invalid procfs arg"));
}
+ cleanups = make_cleanup_close (fd);
sysinfo = (void *) buffer;
if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK)
{
printf_filtered ("Error getting size: %d (%s)\n", errno,
safe_strerror (errno));
- close (fd);
error (_("Devctl failed."));
}
else
{
printf_filtered ("Memory error: %d (%s)\n", errno,
safe_strerror (errno));
- close (fd);
error (_("alloca failed."));
}
else
{
printf_filtered ("Error getting sysinfo: %d (%s)\n", errno,
safe_strerror (errno));
- close (fd);
error (_("Devctl failed."));
}
else
if (sysinfo->type !=
nto_map_arch_to_cputype (gdbarch_bfd_arch_info
(current_gdbarch)->arch_name))
- {
- close (fd);
- error (_("Invalid target CPU."));
- }
+ error (_("Invalid target CPU."));
}
}
}
- close (fd);
+ do_cleanups (cleanups);
printf_filtered ("Debugging using %s\n", nto_procfs_path);
}
return;
}
+static void
+do_closedir_cleanup (void *dir)
+{
+ closedir (dir);
+}
+
void
procfs_pidlist (char *args, int from_tty)
{
DIR *dp = NULL;
struct dirent *dirp = NULL;
- int fd = -1;
char buf[512];
procfs_info *pidinfo = NULL;
procfs_debuginfo *info = NULL;
pid_t num_threads = 0;
pid_t pid;
char name[512];
+ struct cleanup *cleanups;
dp = opendir (nto_procfs_path);
if (dp == NULL)
return;
}
+ cleanups = make_cleanup (do_closedir_cleanup, dp);
+
/* Start scan at first pid. */
rewinddir (dp);
do
{
+ int fd;
+ struct cleanup *inner_cleanup;
+
/* Get the right pid and procfs path for the pid. */
do
{
dirp = readdir (dp);
if (dirp == NULL)
{
- closedir (dp);
+ do_cleanups (cleanups);
return;
}
snprintf (buf, 511, "%s/%s/as", nto_procfs_path, dirp->d_name);
{
fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
buf, errno, safe_strerror (errno));
- closedir (dp);
+ do_cleanups (cleanups);
return;
}
+ inner_cleanup = make_cleanup_close (fd);
pidinfo = (procfs_info *) buf;
if (devctl (fd, DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
if (status->tid != 0)
printf_filtered ("%s - %d/%d\n", name, pid, status->tid);
}
- close (fd);
+
+ do_cleanups (inner_cleanup);
}
while (dirp != NULL);
- close (fd);
- closedir (dp);
+ do_cleanups (cleanups);
return;
}
r = find_and_open_source (s->objfile, s->filename, s->dirname,
&s->fullname);
- if (r)
+ if (r >= 0)
{
close (r);
return s->fullname;
r = find_and_open_source (ps->objfile, ps->filename, ps->dirname,
&ps->fullname);
- if (r)
+ if (r >= 0)
{
close (r);
return ps->fullname;
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)
*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;
}
FILE *stream;
int line;
char *msg;
+ struct cleanup *cleanups;
line = last_line_listed + 1;
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;
}
printf_filtered (_("Expression not found\n"));
- fclose (stream);
+ do_cleanups (cleanups);
}
static void
FILE *stream;
int line;
char *msg;
+ struct cleanup *cleanups;
line = last_line_listed - 1;
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!!! */
}
printf_filtered (_("Expression not found\n"));
- fclose (stream);
+ do_cleanups (cleanups);
return;
}