Skip to content

[Bug]: Dangling pointer access when starting NDI output #908

@norihiro

Description

@norihiro

Operating System Version

Fedora 37

OBS Version

29.1.3-modified

NDI Tools Version

5.5.3

Describe the bug

NDI output does not start with a warning below after restarting video subsystem.

unsupported pixel format -842150451

Log file: https://obsproject.com/logs/KSSuk3oBMBsYYy3T

Steps to reproduce

Add a modification to libobs as below.

diff --git a/libobs/media-io/video-io.c b/libobs/media-io/video-io.c
index afa0fe5c4..996637cbc 100644
--- a/libobs/media-io/video-io.c
+++ b/libobs/media-io/video-io.c
@@ -231,6 +231,8 @@ int video_output_open(video_t **video, struct video_output_info *info)
        if (!out)
                goto fail0;
 
+       blog(LOG_INFO, "video_output_open video=%p", out);
+
        memcpy(&out->info, info, sizeof(struct video_output_info));
        out->frame_time =
                util_mul_div64(1000000000ULL, info->fps_den, info->fps_num);
@@ -281,7 +283,8 @@ void video_output_close(video_t *video)
        pthread_mutex_destroy(&video->data_mutex);
        pthread_mutex_destroy(&video->input_mutex);
 
-       bfree(video);
+       blog(LOG_INFO, "video_output_close video=%p", video);
+       memset(video, 0xCD, sizeof(*video));
 }
 
 static size_t video_get_input_idx(const video_t *video,

Also added modification to obs-ndi-output.cpp to log some information.

diff --git a/src/obs-ndi-output.cpp b/src/obs-ndi-output.cpp
index 5b851bf..6cca20e 100644
--- a/src/obs-ndi-output.cpp
+++ b/src/obs-ndi-output.cpp
@@ -131,6 +131,7 @@ bool ndi_output_start(void *data)
        uint32_t flags = 0;
        video_t *video = obs_output_video(o->output);
        audio_t *audio = obs_output_audio(o->output);
+       blog(LOG_INFO, "ndi_output_start data=%p video=%p", data, video);
 
        if (!video && !audio) {
                blog(LOG_ERROR, "'%s': no video and audio available",
  1. Start OBS
  2. Change video settings (for example, change frame rate.)
  3. Click Tools -> NDI Output settings
  4. Enable Main Output checkbox

Expected behavior

NDI output starts.

Screenshots

No response

Additional context

Found this issue while debugging recording and streaming on OBS Studio that I reported here

Decklink output and AJA output call obs_output_create just before starting it's output so the same issue does not appear.

Using OBS 30.0.0-beta2, above step will cause OBS to crash instead of just not starting NDI output.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions