Skip to content

Commit 1e4aeb6

Browse files
fischman-bcnycompnerd
authored andcommitted
ds2: unbreak network-based non-reverse debugging.
Prior to commit e93f823, the above scenario called `socket->accept().get()` and passed the returned value to RunDebugServer causing the lifetime of the temporary returned by `socket->accept()` to be extended until the end of the RunDebugServer call. Commit e93f823 instead stored the above `.get()`'s returned (raw) pointer in a stack local, allowing `socket->accept()`'s return value to go out of scope before the call to `RunDebugServer`, and since it's a std::unique_ptr, the underlying `Socket` to be freed, making the raw pointer no longer valid. This commit ensures the `accept()`ed Socket is held in a `std::unique_ptr` of its own and outlives the call to `RunDebugServer`.
1 parent 06b8da5 commit 1e4aeb6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,20 @@ static int GdbserverMain(int argc, char **argv) {
470470
ds2::Utils::Daemonize();
471471
}
472472

473-
ds2::Host::Channel *channel;
473+
std::unique_ptr<ds2::Host::Channel> channel;
474474
switch (connection_type) {
475475
case channel_type::file_descriptor:
476476
case channel_type::named_pipe:
477477
case channel_type::network:
478-
channel = (fd >= 0 || reverse) ? socket.get() : socket->accept().get();
478+
if (fd >= 0 || reverse) {
479+
channel.reset(socket.release());
480+
} else {
481+
channel = socket->accept();
482+
}
479483
break;
480484
case channel_type::character_device:
481485
#if defined(OS_POSIX)
482-
channel = device.get();
486+
channel.reset(device.release());
483487
#else
484488
DS2BUG("connecting with chardev is not supported on this platform");
485489
#endif
@@ -495,7 +499,7 @@ static int GdbserverMain(int argc, char **argv) {
495499
else
496500
impl = ds2::make_unique<DebugSessionImpl>();
497501

498-
return RunDebugServer(channel, impl.get());
502+
return RunDebugServer(channel.get(), impl.get());
499503
}
500504

501505
#if !defined(OS_WIN32)

0 commit comments

Comments
 (0)