obsproject / obsproject/obs-studio

Memory leak at reconnecting RTMP

Open
#9,972 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
76.4k
Forks
10.2k
Avg merge
4d 23h
Merged PRs (30d)
12

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in plugins/obs-outputs/rtmp-stream.c at send_thread and review the reconnect path around send_headers and packet ownership. Reproduce the Fedora 37 scenario with nginx and the RTMP module using stream delay and preserve-cutoff enabled. Done means the reconnect-and-exit sequence no longer reports the memory leak, with the correct packet handling verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
audio-video-rtc, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.