Commit 7ea3c31
fix: hold shared_ptr to self in RtpConnection trigger lambda
SendRtpPacket queues a lambda onto the RtspConnection's task scheduler
ring buffer; the scheduler runs it on the event-loop thread later. The
lambda captured raw `this`, so if the RtpConnection was destroyed
between enqueue and execution (client disconnect, session teardown,
shutdown drain) the deferred callback dereferenced freed memory and
crashed deep in the xop send path, with the originating stack pointing
at ZoneMinderFifoSource::WriteRun's PushFrame call.
Make RtpConnection inherit from std::enable_shared_from_this and have
the lambda capture `auto self = shared_from_this()`, so the connection
stays alive at least until every queued trigger has fired. All
RtpConnections are already owned via shared_ptr (RtspConnection::rtp_conn_,
MediaSession::clients_ weak_ptr lifted at the send site), so adopting
shared_from_this here is safe. The same shared-ptr-capture pattern is
already used in TcpConnection::AddTriggerEvent.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent abdf5ad commit 7ea3c31
2 files changed
Lines changed: 17 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
256 | 262 | | |
257 | 263 | | |
258 | | - | |
| 264 | + | |
259 | 265 | | |
260 | | - | |
261 | | - | |
262 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
263 | 269 | | |
264 | 270 | | |
265 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
0 commit comments