obsproject / obs-studio

OBS Studio - Free and open source software for live streaming and screen recording
https://obsproject.com
GNU General Public License v2.0
57.22k stars 7.72k forks source link

Memory leak at reconnecting RTMP #9972

Open norihiro opened 7 months ago

norihiro commented 7 months ago

Operating System Info

Other

Other OS

Fedora 37

OBS Studio Version

Git

OBS Studio Version (Other)

30.0.0-rc1-120-g2d6b6ce05-modified

OBS Studio Log URL

https://obsproject.com/logs/CLbSFxJDmO5eyTqs

OBS Studio Crash Log URL

No response

Expected Behavior

No memory leak

Current Behavior

There is one memory leak

Steps to Reproduce

  1. Configure as below
    • Enable Stream Delay
    • Ensure Preserve cutoff point (increase delay) when reconnecting is enabled (default).
  2. Start nginx with the RTMP module
  3. Start the streaming
  4. Wait until ==== Streaming Start =============================================== is displayed on the log.
  5. Immediately kill the RTMP server
  6. Stop the streaming
  7. Exit OBS

Anything else we should know?

A modification below resolved the memory leak. However, I'm afraid it's the right fix. It might be better to just peek the front packet and drop the packet after the packet has correctly been sent.

diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c
index dab8cdd27..ffbbf4235 100644
--- a/plugins/obs-outputs/rtmp-stream.c
+++ b/plugins/obs-outputs/rtmp-stream.c
@@ -659,6 +659,7 @@ static void *send_thread(void *data)
                if (!stream->sent_headers) {
                        if (!send_headers(stream)) {
                                os_atomic_set_bool(&stream->disconnected, true);
+                               obs_encoder_packet_release(&packet);
                                break;
                        }
                }
### Tasks
norihiro commented 7 months ago

@tt2468, this is the bug we were talking on Discord.