[PR #1016] [MERGED] [Fix] Prevent crash from force unwrapping nil value in PR-1005 #1492

Closed
opened 2026-04-24 23:58:49 +02:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/advplyr/audiobookshelf-app/pull/1016
Author: @KaiStarkk
Created: 12/30/2023
Status: Merged
Merged: 12/31/2023
Merged by: @advplyr

Base: masterHead: hotfix-pr-1005


📝 Commits (1)

  • b2bfa4c [Fix] Prevent crash from force unwrapping nil value in PR #1005

📊 Changes

1 file changed (+12 additions, -9 deletions)

View changed files

📝 ios/App/Shared/player/AudioPlayer.swift (+12 -9)

📄 Description

In further testing I found a rare case where self was not initialized when force unwrapping in the player, causing a runtime crash.
This is now fixed, first self is captured weakly using guard let, to avoid a strong reference cycle, and then safely unwrapped to a strongSelf constant. If self is nil when the closure is called, it will return .commandFailed and exit the closure, avoiding a crash. If self is not nil, it will proceed as per PR #1005.

Wasn't expecting self to ever be cleaned up by the memory manager, but it appears it's possible.
Referenced info on ARC


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/advplyr/audiobookshelf-app/pull/1016 **Author:** [@KaiStarkk](https://github.com/KaiStarkk) **Created:** 12/30/2023 **Status:** ✅ Merged **Merged:** 12/31/2023 **Merged by:** [@advplyr](https://github.com/advplyr) **Base:** `master` ← **Head:** `hotfix-pr-1005` --- ### 📝 Commits (1) - [`b2bfa4c`](https://github.com/advplyr/audiobookshelf-app/commit/b2bfa4c002d92e1ff18b885421fabbad34c32cb1) [Fix] Prevent crash from force unwrapping nil value in PR #1005 ### 📊 Changes **1 file changed** (+12 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `ios/App/Shared/player/AudioPlayer.swift` (+12 -9) </details> ### 📄 Description In further testing I found a rare case where `self` was not initialized when force unwrapping in the player, causing a runtime crash. This is now fixed, first `self `is captured weakly using `guard let`, to avoid a strong reference cycle, and then safely unwrapped to a `strongSelf `constant. If `self `is `nil `when the closure is called, it will return `.commandFailed `and exit the closure, avoiding a crash. If `self `is not nil, it will proceed as per PR #1005. Wasn't expecting self to ever be cleaned up by the memory manager, but it appears it's possible. [Referenced info on ARC](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/automaticreferencecounting/) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-04-24 23:58:49 +02:00
adam closed this issue 2026-04-24 23:58:49 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf-app#1492