aboutsummaryrefslogtreecommitdiff
path: root/gdb/procfs.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2011-11-10 16:36:28 +0000
committerJoel Brobecker <brobecker@gnat.com>2011-11-10 16:36:28 +0000
commite28cade762a84feb67e0864b0e66e380f7cc60d5 (patch)
treeb924ba7e2b17de24d2310e81c15650472a6749de /gdb/procfs.c
parent0a86f36427b729c3b7dfa5a9142848db9877ddc0 (diff)
downloadgdb-e28cade762a84feb67e0864b0e66e380f7cc60d5.zip
gdb-e28cade762a84feb67e0864b0e66e380f7cc60d5.tar.gz
gdb-e28cade762a84feb67e0864b0e66e380f7cc60d5.tar.bz2
procfs file descriptor leaks
gdb/ChangeLog (from Tom Tromey): * procfs.c (load_syscalls): Make a cleanup. (open_procinfo_files): fd==0 is ok.
Diffstat (limited to 'gdb/procfs.c')
-rw-r--r--gdb/procfs.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 2a253a1..4df2610 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -605,7 +605,7 @@ open_procinfo_files (procinfo *pi, int which)
else
strcat (tmp, "/ctl");
fd = open_with_retry (tmp, O_WRONLY);
- if (fd <= 0)
+ if (fd < 0)
return 0; /* fail */
pi->ctl_fd = fd;
break;
@@ -614,7 +614,7 @@ open_procinfo_files (procinfo *pi, int which)
return 0; /* There is no 'as' file descriptor for an lwp. */
strcat (tmp, "/as");
fd = open_with_retry (tmp, O_RDWR);
- if (fd <= 0)
+ if (fd < 0)
return 0; /* fail */
pi->as_fd = fd;
break;
@@ -624,7 +624,7 @@ open_procinfo_files (procinfo *pi, int which)
else
strcat (tmp, "/status");
fd = open_with_retry (tmp, O_RDONLY);
- if (fd <= 0)
+ if (fd < 0)
return 0; /* fail */
pi->status_fd = fd;
break;
@@ -646,13 +646,13 @@ open_procinfo_files (procinfo *pi, int which)
#ifdef PIOCTSTATUS /* OSF */
/* Only one FD; just open it. */
- if ((fd = open_with_retry (pi->pathname, O_RDWR)) == 0)
+ if ((fd = open_with_retry (pi->pathname, O_RDWR)) < 0)
return 0;
#else /* Sol 2.5, Irix, other? */
if (pi->tid == 0) /* Master procinfo for the process */
{
fd = open_with_retry (pi->pathname, O_RDWR);
- if (fd <= 0)
+ if (fd < 0)
return 0; /* fail */
}
else /* LWP thread procinfo */
@@ -666,7 +666,7 @@ open_procinfo_files (procinfo *pi, int which)
return 0; /* fail */
/* Now obtain the file descriptor for the LWP. */
- if ((fd = ioctl (process->ctl_fd, PIOCOPENLWP, &lwpid)) <= 0)
+ if ((fd = ioctl (process->ctl_fd, PIOCOPENLWP, &lwpid)) < 0)
return 0; /* fail */
#else /* Irix, other? */
return 0; /* Don't know how to open threads. */
@@ -878,6 +878,7 @@ load_syscalls (procinfo *pi)
prsysent_t header;
prsyscall_t *syscalls;
int i, size, maxcall;
+ struct cleanup *cleanups;
pi->num_syscalls = 0;
pi->syscall_names = 0;
@@ -889,6 +890,7 @@ load_syscalls (procinfo *pi)
{
error (_("load_syscalls: Can't open /proc/%d/sysent"), pi->pid);
}
+ cleanups = make_cleanup_close (sysent_fd);
size = sizeof header - sizeof (prsyscall_t);
if (read (sysent_fd, &header, size) != size)
@@ -904,12 +906,10 @@ load_syscalls (procinfo *pi)
size = header.pr_nsyscalls * sizeof (prsyscall_t);
syscalls = xmalloc (size);
+ make_cleanup (free_current_contents, &syscalls);
if (read (sysent_fd, syscalls, size) != size)
- {
- xfree (syscalls);
- error (_("load_syscalls: Error reading /proc/%d/sysent"), pi->pid);
- }
+ error (_("load_syscalls: Error reading /proc/%d/sysent"), pi->pid);
/* Find maximum syscall number. This may not be the same as
pr_nsyscalls since that value refers to the number of entries
@@ -963,8 +963,7 @@ load_syscalls (procinfo *pi)
pi->syscall_names[callnum][size-1] = '\0';
}
- close (sysent_fd);
- xfree (syscalls);
+ do_cleanups (cleanups);
}
/* Free the space allocated for the syscall names from the procinfo