gdbstub: Fix fd leak in gdbserver_open() error path

Fix a leak of a file descriptor in error exit paths in
gdbserver_open().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
This commit is contained in:
Peter Maydell 2011-12-24 23:37:24 +00:00 committed by Stefan Hajnoczi
parent 359bc95d3e
commit bb16172c52

View File

@ -2762,11 +2762,13 @@ static int gdbserver_open(int port)
ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
if (ret < 0) { if (ret < 0) {
perror("bind"); perror("bind");
close(fd);
return -1; return -1;
} }
ret = listen(fd, 0); ret = listen(fd, 0);
if (ret < 0) { if (ret < 0) {
perror("listen"); perror("listen");
close(fd);
return -1; return -1;
} }
return fd; return fd;