From 87206fca67b449685da294e9e3e6c4269d3c1273 Mon Sep 17 00:00:00 2001 From: David Reid Date: Mon, 13 Jul 2026 08:39:19 +1000 Subject: [PATCH] Resource Manager: Fix a possible crash when loading fails. Public issue: https://github.com/mackron/miniaudio/issues/1129 --- CHANGES.md | 1 + miniaudio.h | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 478e0616..224df8e1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ v0.11.26 - TBD * Fixed a crash when passing in null for the read or seek callbacks for a decoder. * Fixed an error with node initialization. * Fixed build for Arm64EC on MSVC. +* Resource Manager: Fixed a possible crash when loading fails. * PulseAudio: Improvements to format negotiation to better handle cases when PulseAudio reports s24_32 as its native format. * Emscripten: Fixed an error with ALLOW_MEMORY_GROWTH. * Emscripten: Fixed some issues relating to handling of 64-bit pointers. diff --git a/miniaudio.h b/miniaudio.h index 20130fb4..2a54eaa6 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -71042,21 +71042,26 @@ static ma_result ma_resource_manager_data_buffer_node_acquire(ma_resource_manage } done: - /* If we failed to initialize the data buffer we need to free it. */ - if (result != MA_SUCCESS) { - if (nodeAlreadyExists == MA_FALSE) { - ma_resource_manager_data_buffer_node_remove(pResourceManager, pDataBufferNode); - ma_free(pDataBufferNode, &pResourceManager->config.allocationCallbacks); - } - } + { + ma_bool32 isDataOwnedByResourceManager = pDataBufferNode->isDataOwnedByResourceManager; - /* - The init notification needs to be uninitialized. This will be used if the node does not already - exist, and we've specified ASYNC | WAIT_INIT. - */ - if (nodeAlreadyExists == MA_FALSE && pDataBufferNode->isDataOwnedByResourceManager && (flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC) != 0) { - if ((flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT) != 0) { - ma_resource_manager_inline_notification_uninit(&initNotification); + /* If we failed to initialize the data buffer we need to free it. */ + if (result != MA_SUCCESS) { + if (nodeAlreadyExists == MA_FALSE) { + ma_resource_manager_data_buffer_node_remove(pResourceManager, pDataBufferNode); + ma_free(pDataBufferNode, &pResourceManager->config.allocationCallbacks); + pDataBufferNode = NULL; + } + } + + /* + The init notification needs to be uninitialized. This will be used if the node does not already + exist, and we've specified ASYNC | WAIT_INIT. + */ + if (nodeAlreadyExists == MA_FALSE && isDataOwnedByResourceManager && (flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC) != 0) { + if ((flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT) != 0) { + ma_resource_manager_inline_notification_uninit(&initNotification); + } } }