Fix heap-use-after-free when processing incoming RTP/RTCP after stream destroy#4790
Fix heap-use-after-free when processing incoming RTP/RTCP after stream destroy#4790
Conversation
There was a problem hiding this comment.
Pull request overview
This PR attempts to prevent a heap-use-after-free when late incoming RTCP/RTP packets are processed after pjmedia_stream_destroy() (likely exposed by the async-callback behavior enabled by #4721).
Changes:
- Modifies the common stream destroy handler to defer stream cleanup by registering
on_destroy()onto the transport’sgrp_lock. - Removes the direct transport
grp_lockderef previously done during stream cleanup.
…er stream destroy" This reverts commit 3e3c204.
Other streams (video, text) need to be updated later after this approach is reviewed.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
pjmedia/src/pjmedia/stream_imp_common.c:675
- on_destroy() ultimately releases c_strm->own_pool. With the stream now registering on_destroy on the transport grp_lock, this cleanup won’t run until the transport grp_lock is destroyed, so the stream’s pool/name strings remain alive long after pjmedia_stream_destroy() returns. If this is intentional to avoid the callback race, it would be good to restructure so the heavy stream teardown happens during pjmedia_stream_destroy() and only the final pool release is deferred, to avoid holding codec/JB resources for the lifetime of the transport.
/* Call specific stream destroy handler. */
on_stream_destroy(arg);
/* Free mutex */
if (c_strm->jb_mutex) {
pj_mutex_destroy(c_strm->jb_mutex);
c_strm->jb_mutex = NULL;
}
/* Destroy jitter buffer */
if (c_strm->jb) {
pjmedia_jbuf_destroy(c_strm->jb);
c_strm->jb = NULL;
}
/* Destroy media synchronizer */
if (c_strm->av_sync && c_strm->av_sync_media)
pjmedia_stream_common_set_avsync(c_strm, NULL);
#if TRACE_JB
if (TRACE_JB_OPENED(c_strm)) {
pj_file_close(c_strm->trace_jb_fd);
c_strm->trace_jb_fd = TRACE_JB_INVALID_FD;
}
#endif
PJ_LOG(4,(c_strm->port.info.name.ptr, "Stream destroyed"));
pj_pool_safe_release(&c_strm->own_pool);
}
|
It seems like we're just going in circles. We have used this approach before: #4184 |
|
IMO I think we should sync |
Oops, I forgot we've been there before. |
Good idea. Adding busy waiting in |
|
Yes, I suppose if |
This reverts commit 66d48d0.
…callback wait Co-authored-by: sauwming <17044930+sauwming@users.noreply.github.com>
Co-authored-by: sauwming <17044930+sauwming@users.noreply.github.com>
As reported by ASan:
This is perhaps related to the new behavior introduced by #4721, media transport detach is now asynchronous.