fix(bt): fixed mempool deinit crash issue

This commit is contained in:
ShenWeilong
2026-08-27 16:50:22 +08:00
parent a7c07eb28f
commit b66fa4551f
4 changed files with 47 additions and 3 deletions
@@ -358,6 +358,29 @@ void os_mempool_flags_set(struct os_mempool *mp, uint8_t flags);
*/
void os_mempool_flags_clear(struct os_mempool *mp, uint8_t flags);
/**
* @brief Deinitialize a memory pool.
*
* @param mp Pointer to memory pool
*/
void os_mempool_deinit(struct os_mempool *mp);
/**
* @brief Deinitialize all of memory pools.
*
* @param is_controller Whether called from controller.
*
* @return OS_OK on success; OS_INVALID_PARM if not found corresponding memory pools.
*/
os_error_t os_mempool_deinit_all(bool is_controller);
/**
* @brief Check if there are any live memory pools.
*
* @return true if there are any live memory pools; false otherwise.
*/
bool os_mempool_has_live_pool(void);
#ifdef __cplusplus
}
#endif
+22 -1
View File
@@ -735,6 +735,11 @@ os_mempool_module_init(void)
static os_error_t
os_mempool_mem_free(struct os_mempool *mp)
{
/* Extended mempool has its own free logic */
if (mp->mp_flags & OS_MEMPOOL_F_EXT) {
return OS_OK;
}
/* For runtime allocation mode, check whether all blocks have been freed */
if (!(mp->mp_flags & OS_MEMPOOL_F_RUNTIME)) {
return OS_EINVAL;
@@ -767,8 +772,15 @@ os_mempool_mem_free(struct os_mempool *mp)
#endif
void
os_mempool_deinit(bool is_controller)
os_mempool_deinit(struct os_mempool *mp)
{
os_mempool_unregister(mp);
}
os_error_t
os_mempool_deinit_all(bool is_controller)
{
os_error_t err = OS_INVALID_PARM;
struct os_mempool *mp = NULL;
struct os_mempool *next = NULL;
@@ -780,8 +792,17 @@ os_mempool_deinit(bool is_controller)
next = STAILQ_NEXT(mp, mp_list);
os_mempool_unregister(mp);
mp = next;
err = OS_OK;
} else {
mp = STAILQ_NEXT(mp, mp_list);
}
}
return err;
}
bool
os_mempool_has_live_pool(void)
{
return !STAILQ_EMPTY(&g_os_mempool_list);
}