gdbstub: Fix double close() of the follow-fork-mode socket
When the terminal GDB_FORK_ENABLED state is reached, the coordination
socket is not needed anymore and is therefore closed. However, if there
is a communication error between QEMU gdbstub and GDB, the generic
error handling code attempts to close it again.
Fix by closing it later - before returning - instead.
Fixes: Coverity CID 1539966
Fixes: d547e711a8
("gdbstub: Implement follow-fork-mode child")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240312001813.13720-1-iii@linux.ibm.com>
This commit is contained in:
parent
bbc0543b1b
commit
6971998e24
@ -517,6 +517,7 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
|
|||||||
switch (gdbserver_user_state.fork_state) {
|
switch (gdbserver_user_state.fork_state) {
|
||||||
case GDB_FORK_ENABLED:
|
case GDB_FORK_ENABLED:
|
||||||
if (gdbserver_user_state.running_state) {
|
if (gdbserver_user_state.running_state) {
|
||||||
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QEMU_FALLTHROUGH;
|
QEMU_FALLTHROUGH;
|
||||||
@ -542,7 +543,6 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
|
|||||||
gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
|
gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
|
||||||
break;
|
break;
|
||||||
case GDB_FORK_ENABLE:
|
case GDB_FORK_ENABLE:
|
||||||
close(fd);
|
|
||||||
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
|
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
|
||||||
break;
|
break;
|
||||||
case GDB_FORK_DISABLE:
|
case GDB_FORK_DISABLE:
|
||||||
@ -557,7 +557,6 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
|
|||||||
if (write(fd, &b, 1) != 1) {
|
if (write(fd, &b, 1) != 1) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
close(fd);
|
|
||||||
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
|
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
|
||||||
break;
|
break;
|
||||||
case GDB_FORK_DISABLING:
|
case GDB_FORK_DISABLING:
|
||||||
|
Loading…
Reference in New Issue
Block a user