summaryrefslogtreecommitdiff
path: root/gdb/ser-pipe.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2010-04-20 05:52:06 +0000
committerDoug Evans <dje@google.com>2010-04-20 05:52:06 +0000
commit07ed1d58ab86b51ff98fc9b4f9f6104ea6a2edea (patch)
tree1486f311e0f049bc26d0535eede2c44735f1eb50 /gdb/ser-pipe.c
parente38d9943877fcd65c83701b901fc9c4ddfa4bf77 (diff)
downloadgdb-07ed1d58ab86b51ff98fc9b4f9f6104ea6a2edea.tar.gz
* ser-base.c (generic_readchar): Watch for EOF in read of error_fd.
* ser-pipe.c (pipe_open): Fix file descriptor leaks. (pipe_close): Ditto.
Diffstat (limited to 'gdb/ser-pipe.c')
-rw-r--r--gdb/ser-pipe.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index e0454d4c17c..77c3a08e9a9 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -66,7 +66,11 @@ pipe_open (struct serial *scb, const char *name)
if (socketpair (AF_UNIX, SOCK_STREAM, 0, pdes) < 0)
return -1;
if (socketpair (AF_UNIX, SOCK_STREAM, 0, err_pdes) < 0)
- return -1;
+ {
+ close (pdes[0]);
+ close (pdes[1]);
+ return -1;
+ }
/* Create the child process to run the command in. Note that the
apparent call to vfork() below *might* actually be a call to
@@ -123,6 +127,8 @@ pipe_open (struct serial *scb, const char *name)
/* Parent. */
close (pdes[1]);
+ if (err_pdes[1] != -1)
+ close (err_pdes[1]);
/* :end chunk */
state = XMALLOC (struct pipe_state);
state->pid = pid;
@@ -145,10 +151,15 @@ pipe_close (struct serial *scb)
int pid = state->pid;
close (scb->fd);
scb->fd = -1;
+ if (scb->error_fd != -1)
+ close (scb->error_fd);
+ scb->error_fd = -1;
xfree (state);
scb->state = NULL;
kill (pid, SIGTERM);
- /* Might be useful to check that the child does die. */
+ /* Might be useful to check that the child does die,
+ and while we're waiting for it to die print any remaining
+ stderr output. */
}
}