obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

libobs: Should not free audio_output before clearing view->channels

Open walker-WSH opened this issue 3 years ago • 5 comments

Description

When stop_audio() is called, view->channels has not been cleared yet, where maybe storage global output/input audio source. So variables related with audio should not be deleted in stop_audio().

Motivation and Context

fix possible crash

How Has This Been Tested?

enable global desktop audio, exit OBS

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

walker-WSH avatar May 31 '22 00:05 walker-WSH

Are there reproduction steps for the fixed crash or is it just possible?

tt2468 avatar Jul 25 '22 11:07 tt2468

Are there reproduction steps for the fixed crash or is it just possible?

Just possible and I meet this crash once. Difficult to reproduce

walker-WSH avatar Jul 26 '22 07:07 walker-WSH

Even if it's difficult to reproduce, could you describe how view->channels holds the global audio sources when entering obs_shutdown()? If there is a possibility to cause a crash, I think it is important to fix.

I've added a log message entering stop_audio... at the beginning of stop_audio() and entering obs_source_destroy... at the beginning of obs_source_destroy(). Then checked which is called earlier. On my run, obs_source_destroy() is called earlier.

My understanding is that obs_shutdown() is called after all sources are destroyed. And also obs_wait_for_destroy_queue() at the beginning of obs_shutdown() waits audio thread has exited.

Just in case a reference-count of a source is not correctly decremented, it is a memory leak rather than an invalid order of the shutdown.

norihiro avatar Jul 26 '22 10:07 norihiro

view->channels

view->channels holds the reference of root source, and it is released in obs_main_view_free. However, obs_main_view_free is called after stop_audio().

@norihiro

walker-WSH avatar Aug 09 '22 04:08 walker-WSH

view->channels holds the reference of root source, and it is released in obs_main_view_free. However, obs_main_view_free is called after stop_audio().

Before stop_audio, OBSBasic::ClearSceneData() should have released the main-views. The main-views should not be a concern.

https://github.com/obsproject/obs-studio/blob/b4f7499b33b53351e56a02fc6194f11d8af78da5/UI/window-basic-main.cpp#L4640-L4641

AFAIK, if script or third party plugins have not released a reference-count of an audio source, stop_audio() might fail. However I feel such a scenario is not a fault of the shutdown process but a memory leak.

norihiro avatar Aug 10 '22 11:08 norihiro

view->channels holds the reference of root source, and it is released in obs_main_view_free. However, obs_main_view_free is called after stop_audio().

Before stop_audio, OBSBasic::ClearSceneData() should have released the main-views. The main-views should not be a concern.

https://github.com/obsproject/obs-studio/blob/b4f7499b33b53351e56a02fc6194f11d8af78da5/UI/window-basic-main.cpp#L4640-L4641

AFAIK, if script or third party plugins have not released a reference-count of an audio source, stop_audio() might fail. However I feel such a scenario is not a fault of the shutdown process but a memory leak.

sorry to response late.

yes, this crash is because of another scenario that any source has not been released completely until stop_audio().

Now I agree with you to ignore this crash. I will close it. Thannks ~

walker-WSH avatar Nov 24 '22 01:11 walker-WSH