Repository navigation
Description
Upstream OBS bug, found by pobrn with AddressSanitizer and a removable USB camera and fixed in their open PR obsproject/obs-studio#13698 (opened 2026-07-25, approved by tytan652 the same day, not merged). There is no upstream issue for it. The code is unchanged upstream and in this fork.
Location
plugins/linux-pipewire/camera-portal.clines 1032-1033,on_registry_global_remove_cb():g_hash_table_iter_remove()removes the unplugged device fromconnection->devices, thenblog()logsdevice_id, which is that entry's key.- Same file, line 1141: the table is created with
bfreeas its key destructor, so the key is freed by the remove, before it is logged. The key is thebstrdup()of the device's node name from line 1010.
Class
Use-after-free (read of a freed string, on the PipeWire thread).
How it is reached
- Add a "Video Capture Device (PipeWire)" source (any camera, any selected device).
- Unplug a camera that PipeWire lists.
Every unplug logs [pipewire-camera] Removed device ... from freed memory. Depending on the allocator, the log line shows a corrupted name or the old one; under AddressSanitizer OBS aborts, with the trace in the upstream PR: freed at line 1032, read at line 1033.
Reproduced headless here: the real camera portal code against a fake org.freedesktop.portal.Camera on a private D-Bus bus and a private PipeWire daemon (own runtime dir, no session manager, no devices), with a video source node in the test playing the camera. Unplugging it (destroying the node) logs Removed device XXXXXXXXXXXXXXX instead of the node's name when freed keys are overwritten, and AddressSanitizer reports the same heap-use-after-free as the upstream report.
Proposed fix and failing test
Fix: log the device before removing it from the table (pobrn's patch from obsproject/obs-studio#13698, ported with them as the author).
RED test (cmocka, test_pipewire_camera_unplug, Linux, private PipeWire and private D-Bus, X display for obs_startup(); skips without them): plugs the test camera in, waits for the camera portal to list it, unplugs it and checks the log line. The test links with --wrap so it sees the camera portal's device ids being freed: a freed id is overwritten with 'X' and, without AddressSanitizer, kept allocated until the end, so the failure is deterministic in a normal build. 1 of 2 cases fails today (the guard, that the camera is listed, passes); under AddressSanitizer the process aborts at the read.
Not part of this issue:
pipewire_camera_destroy()(libobs's destruction thread) andaccess_camera()changeconnection->sourceswithout the PipeWire loop lock while the registry callbacks iterate it on the PipeWire thread; the device table is also read from the UI thread while the PipeWire thread changes it. Unloading the module destroys the device proxies without the loop lock (PipeWire warnsimpl_ext_end_proxy called from wrong context). Real, but narrow and not deterministic; no user report.- Startup crash in camera portal: on_registry_global_cb reads connection->obs_pw before it is assigned obsproject/obs-studio#13971 (TheMorpheus407, closed upstream): a startup race in which
on_registry_global_cb()readsconnection->obs_pwbefore it is assigned. The test holds the registry events until the camera portal's first roundtrip so that race cannot crash it.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 12, 2026
Claiming: this issue.
test_pipewire_camera_unplug(1 of 2 failing without ASan; heap-use-after-free under ASan): the real camera portal code against a fake Camera portal and a private PipeWire; unplugging the camera node must log its real id, not freed memory.PR today.
linux-pipewire: Fix use-after-free in log message
test/cmocka: Add a failing test for unplugging a PipeWire camera
linux-pipewire: Fix use-after-free in log message
linux-pipewire: Fix use-after-free in log message (#393)