Skip to content

libobs: Free an empty default sink name in get_default_id - #417

Merged
zackees merged 3 commits into
masterfrom
fix/158-pulse-default-sink-leak
Oct 13, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/158-pulse-default-sink-leak

Conversation

@zackees

@zackees zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Closes #158.

get_default_id() (libobs/audio-monitoring/pulse/pulseaudio-wrapper.c) freed the bstrdup copy of the server's default sink name only on the non-empty branch. With no default sink (no sinks, a headless or CI box, a removed null sink), every devices_match() call leaked it: once on source creation and once per device change.

  • RED: new cmocka test test_pulse_default_id. It compiles pulseaudio-wrapper.c against a fake libpulse defined in the test (pulse headers only, no libpulse link, no sound server). The fake context is always ready and reports the default sink the test picks. The test compares bnum_allocs() around get_default_id + bfree: the named-sink case was 0, the empty-sink case leaked 1.
  • GREEN: bfree(pdo->default_sink_name) after both branches (bfree is NULL-safe).

Tier 2: 138/138 pass with ENABLE_RUST_LIBOBS OFF and ON. The local gate passed and is stamped.

pulseaudio-wrapper.c runs against a fake libpulse defined in the test,
which reports the default sink the test picks.

Refs #158
The bstrdup copy of the server's default sink name was freed only when
it was non-empty, so every device check on a box with no default sink
leaked it.

Closes #158
Refs #158

Local-Gate: v1 tree=68bdf02490cacbf5b6d28aabe253bb65bfd03412 secs=139 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791852329,"gate":"rust/all/fmt","host":"linux-x86_64","key":"708a09fd51cdde64923fa4d32d10ebbde3e356cebec931f05905039c0a4138b4","lane":"lint","parents":["09c990874b9837349b57708f2c6a58f1ddafaabc"],"secs":16,"stamp":"d408d6b221eb7a80136a231d124f9146","tree":"68bdf02490cacbf5b6d28aabe253bb65bfd03412","v":1,"via":"run"}
Ci-Attestation: {"at":1791852329,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"708a09fd51cdde64923fa4d32d10ebbde3e356cebec931f05905039c0a4138b4","lane":"lint","parents":["09c990874b9837349b57708f2c6a58f1ddafaabc"],"secs":16,"stamp":"1c16486c892358c7b04fb5b06d0f69e2","tree":"68bdf02490cacbf5b6d28aabe253bb65bfd03412","v":1,"via":"run"}
Ci-Attestation: {"at":1791852329,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"63ff3cedd96eb0d302b579b0ffdbd1b54dd22f68b883736bbe1331c5f99f2ae8","lane":"rust-test","parents":["09c990874b9837349b57708f2c6a58f1ddafaabc"],"secs":58,"stamp":"d97306f8ce78e82fa6185dd6f645d4e2","tree":"68bdf02490cacbf5b6d28aabe253bb65bfd03412","v":1,"via":"run"}
Ci-Attestation: {"at":1791852329,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"dbec523e698d18813f25ff1eaaad39754e5c0108bfbc4ffe70677d88862d20c9","lane":"tier2-linux","parents":["09c990874b9837349b57708f2c6a58f1ddafaabc"],"secs":64,"stamp":"bad0b1ac8829fff11083696d6b3d27d7","tree":"68bdf02490cacbf5b6d28aabe253bb65bfd03412","v":1,"via":"run"}
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Correction: the first push went out with a clang-format violation in the new test, so it was not stamped despite what the description said. It's fixed in a follow-up commit (test: Format test_pulse_default_id.c), and the local gate now passes and is stamped on the new head.

@zackees
zackees merged commit d769a9b into master Oct 13, 2026
45 of 46 checks passed
@zackees
zackees deleted the fix/158-pulse-default-sink-leak branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

libobs pulse: get_default_id leaks the sink name when the default sink name is empty

1 participant