LibWeb: Protect audio codec callbacks against its own destruction

The plugin may go out of scope before the callbacks we've queued have
fired. It is undefined behavior for these callbacks to access the plugin
data after that has occurred.

This patch protects these callbacks with weak pointers. Note that the
plugin is not ref-counted, so we cannot use `strong_ref` here.
This commit is contained in:
Timothy Flynn 2025-03-14 09:19:03 -04:00 committed by Andreas Kling
commit 9586a7500c
Notes: github-actions[bot] 2025-03-14 17:03:21 +00:00
2 changed files with 48 additions and 25 deletions

View file

@ -10,11 +10,12 @@
#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Weakable.h>
#include <LibMedia/Audio/Forward.h>
namespace Web::Platform {
class AudioCodecPlugin {
class AudioCodecPlugin : public Weakable<AudioCodecPlugin> {
public:
using AudioCodecPluginCreator = Function<ErrorOr<NonnullOwnPtr<AudioCodecPlugin>>(NonnullRefPtr<Audio::Loader>)>;