Skip to content

Commit 47fb2d1

Browse files
Fixed possible crash when user-space destructs the context when handling a tcp response
1 parent 8ccd498 commit 47fb2d1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ INCLUDE_DIR = ${PREFIX}/include
33
LIBRARY_DIR = ${PREFIX}/lib
44
export LIBRARY_NAME = dnscpp
55
export SONAME = 1.3
6-
export VERSION = 1.3.4
6+
export VERSION = 1.3.5
77

88
all:
99
$(MAKE) -C src all

src/sockets.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ size_t Sockets::deliver(size_t maxcalls)
107107
// when responses from tcp sockets are delivered, it is possible that at the same
108108
// time those sockets are removed from the underlying array (by the onUnused() method),
109109
// to ensure that we can use a simple iterator, we make a copy of the sockets
110-
auto sockets = _tcps;
110+
// (note that the Tcp object has smarty detection of user-space destruction, so we
111+
// cannot make a normal copy of the shared_ptr<Tcp> here, as that would keep the
112+
// object in space)
113+
std::vector<Tcp*> sockets;
114+
115+
// micro-optimization
116+
sockets.reserve(_tcps.size());
117+
118+
// copy them one at a time
119+
for (const auto &socket : _tcps) sockets.push_back(socket.get());
111120

112121
// deliver the buffer from all tcp sockets
113122
for (auto &socket : sockets)

0 commit comments

Comments
 (0)