AudioContext destructor dereferences a null audioPlayer_ when construction fails before initialize()
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- android, cpp, ios, react-native
调研方向
从 packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.cpp 开始,查看 isDriverRunning() 和析构函数,并跟踪 BaseAudioContext::getState() 如何调用 isDriverRunning()。在 initialize() 给 audioPlayer_ 赋值之前让构造抛出异常以复现问题,然后确认空指针解引用。当析构函数和 isDriverRunning() 在 audioPlayer_ 为空时是安全的,并且现有音频测试仍然通过时,即完成。
由索引模型根据 Issue 内容生成。
描述
Description
When an AudioContext is destroyed before initialize() has created its platform player, its destructor dereferences the null audioPlayer_ and the app crashes (EXC_BAD_ACCESS at a small offset such as 0x44). A failed construction — a C++ exception thrown while the host object is being built — therefore becomes a native crash instead of a JS error at new AudioContext().
Path (production crash reports, iOS):
AudioAPIModuleInstaller.h:84 make_shared<AudioContextHostObject>(...)
AudioContextHostObject.cpp:18 (construction unwinds)
std::shared_ptr<AudioContext>::~shared_ptr
AudioContext::~AudioContext (AudioContext.cpp:23)
BaseAudioContext::getState (BaseAudioContext.cpp:54)
AudioContext::isDriverRunning → audioPlayer_->isRunning() // audioPlayer_ == nullptr
IOSAudioPlayer::isRunning (IOSAudioPlayer.mm:167) // EXC_BAD_ACCESS
audioPlayer_ is only assigned in AudioContext::initialize(). The same code is on main today (packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.cpp):
~AudioContext()callsgetState(), andstopDriver()when not closed;BaseAudioContext::getState()callsisDriverRunning()unless the state isCLOSED;AudioContext::isDriverRunning()isreturn audioPlayer_->isRunning();with no null check (unlikegetBaseLatency()next to it, which checksaudioPlayer_ == nullptr).
Suggested fix (what we ship as a local patch on 0.13.5):
bool AudioContext::isDriverRunning() const {
return audioPlayer_ != nullptr && audioPlayer_->isRunning();
}
AudioContext::~AudioContext() {
// Never initialised: no player, nothing was started, nothing to stop.
if (audioPlayer_ != nullptr && getState() != ContextState::CLOSED) {
close(); // stopDriver() on main
}
}
Steps to reproduce
- Make anything throw while the
AudioContextHostObjectis being constructed, after theAudioContextmember exists and beforeinitialize()assignsaudioPlayer_(in production this happens on memory-starved devices; in a debug build, e.g. throw fromBaseAudioContext::initialize). new AudioContext()from JS.- The app crashes in
IOSAudioPlayer::isRunningfrom~AudioContextinstead ofnew AudioContext()throwing.
Snack or a link to a repository
No standalone reproducer: the path needs construction to fail part-way, which a Snack cannot force without patching the library. The code path above is deterministic once that happens. Happy to open a PR with the two-line fix if that is welcome.
React Native Audio API version
0.13.5 (code unchanged on main / 1.0.1)
React Native version
0.88.0
Platforms
iOS (the destructor is shared C++, so Android is exposed too)
JavaScript runtime
Hermes
Workflow
Expo (prebuild)
Architecture
New Architecture (Fabric)
Build type
Release
Device
Real device
Device model
iPad (9th gen), iPad Air (M2-class); iPadOS 26–27; low free memory (~110 MB)
- 主要语言
- C++
- 星标
- 864
- 派生
- 103
- 平均合并
- 1 天 16 小时
- 30 天内合并 PR
- 77
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
software-mansion/react-native-audio-api 的其他 Issue
-
bug ios
难度 2/5 1-3 小时 新手友好度 78/100
software-mansion/react-native-audio-api#1238 · 1 条评论 ·
维护者通常 1 天内回复
-
Closed AudioContext / OfflineAudioContext is never released: stateChange listener is never unregistered可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 4/5 1-2 天 新手友好度 35/100
software-mansion/react-native-audio-api#1497 · 1 条评论 ·
维护者通常 1 天内回复
-
android bug
难度 4/5 3-5 天 新手友好度 20/100
software-mansion/react-native-audio-api#1494 · 3 条评论 ·
维护者通常 1 天内回复
-
DelayNode: signals connected to delayTime are ignored, and delayTime = 0 delays by maxDelayTime可能已有人在做 @mdydek 于 6 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 30/100
software-mansion/react-native-audio-api#1491 ·
维护者通常 1 天内回复
-
[Android] AudioRecorder reopens a disconnected input stream with no limit: a re-route on every open (Samsung, concurrent capture) loops hundreds of times a minute and records nothing可能已有人在做 @maciejmakowski2003 于 18 天前认领。 未关闭android bug
难度 4/5 3-5 天 新手友好度 48/100
software-mansion/react-native-audio-api#1416 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 software-mansion/react-native-audio-api 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
component: tabs platform: macOS
难度 2/5 1-3 小时 新手友好度 72/100
zen-browser/desktop#16860 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
metasequoiaime/msime#12003 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
windirstat/windirstat#776 ·
维护者通常 2 天内回复