Skip to content

Commit 7e513bc

Browse files
committed
unify return values for destroy functions
fixes: #1217
1 parent 370c281 commit 7e513bc

34 files changed

+224
-95
lines changed

include/umf/memory_pool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
5858
///
5959
/// @brief Destroys memory pool.
6060
/// @param hPool handle to the pool
61+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
6162
///
62-
void umfPoolDestroy(umf_memory_pool_handle_t hPool);
63+
umf_result_t umfPoolDestroy(umf_memory_pool_handle_t hPool);
6364

6465
///
6566
/// @brief Allocates \p size bytes of uninitialized storage from \p hPool

include/umf/memory_pool_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct umf_memory_pool_ops_t {
4848
/// @brief Finalizes memory pool
4949
/// @param pool pool to finalize
5050
///
51-
void (*finalize)(void *pool);
51+
umf_result_t (*finalize)(void *pool);
5252

5353
///
5454
/// @brief Allocates \p size bytes of uninitialized storage from \p pool

include/umf/memory_provider.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
5151
///
5252
/// @brief Destroys memory provider.
5353
/// @param hProvider handle to the memory provider
54+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
5455
///
55-
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
56+
umf_result_t umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
5657

5758
///
5859
/// @brief Allocates \p size bytes of uninitialized storage from memory \p hProvider

include/umf/memory_provider_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct umf_memory_provider_ops_t {
4343
/// @brief Finalizes memory provider.
4444
/// @param provider provider to finalize
4545
///
46-
void (*finalize)(void *provider);
46+
umf_result_t (*finalize)(void *provider);
4747

4848
///
4949
/// @brief Allocates \p size bytes of uninitialized storage from memory \p provider

include/umf/memspace.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -58,8 +58,9 @@ umf_result_t umfMemspaceCreateFromNumaArray(unsigned *nodeIds, size_t numIds,
5858
///
5959
/// \brief Destroys memspace
6060
/// \param hMemspace handle to memspace
61+
/// \return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
6162
///
62-
void umfMemspaceDestroy(umf_memspace_handle_t hMemspace);
63+
umf_result_t umfMemspaceDestroy(umf_memspace_handle_t hMemspace);
6364

6465
///
6566
/// \brief Retrieves predefined host all memspace.

include/umf/pools/pool_disjoint.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ umfDisjointPoolSharedLimitsCreate(size_t MaxSize);
3535

3636
/// @brief Destroy previously created pool limits struct.
3737
/// @param hSharedLimits handle to the shared limits struct.
38-
void umfDisjointPoolSharedLimitsDestroy(
38+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
39+
umf_result_t umfDisjointPoolSharedLimitsDestroy(
3940
umf_disjoint_pool_shared_limits_handle_t hSharedLimits);
4041

4142
/// @brief Create a struct to store parameters of disjoint pool.

src/memory_pool.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,31 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
201201
return ret;
202202
}
203203

204-
void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
204+
umf_result_t umfPoolDestroy(umf_memory_pool_handle_t hPool) {
205205
if (umf_ba_global_is_destroyed()) {
206-
return;
206+
return UMF_RESULT_ERROR_UNKNOWN;
207207
}
208208

209-
hPool->ops.finalize(hPool->pool_priv);
209+
umf_result_t ret = UMF_RESULT_SUCCESS;
210+
if (hPool->ops.finalize(hPool->pool_priv) != UMF_RESULT_SUCCESS) {
211+
ret = UMF_RESULT_ERROR_UNKNOWN;
212+
}
210213

211214
umf_memory_provider_handle_t hUpstreamProvider = NULL;
212215
umfPoolGetMemoryProvider(hPool, &hUpstreamProvider);
213216

214217
if (!(hPool->flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING)) {
215218
// Destroy tracking provider.
216-
umfMemoryProviderDestroy(hPool->provider);
219+
if (umfMemoryProviderDestroy(hPool->provider) != UMF_RESULT_SUCCESS) {
220+
ret = UMF_RESULT_ERROR_UNKNOWN;
221+
}
217222
}
218223

219224
if (hPool->flags & UMF_POOL_CREATE_FLAG_OWN_PROVIDER) {
220225
// Destroy associated memory provider.
221-
umfMemoryProviderDestroy(hUpstreamProvider);
226+
if (umfMemoryProviderDestroy(hUpstreamProvider) != UMF_RESULT_SUCCESS) {
227+
ret = UMF_RESULT_ERROR_UNKNOWN;
228+
}
222229
}
223230

224231
utils_mutex_destroy_not_free(&hPool->lock);
@@ -227,6 +234,7 @@ void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
227234

228235
// TODO: this free keeps memory in base allocator, so it can lead to OOM in some scenarios (it should be optimized)
229236
umf_ba_global_free(hPool);
237+
return ret;
230238
}
231239

232240
umf_result_t umfFree(void *ptr) {

src/memory_provider.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,18 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
235235
return UMF_RESULT_SUCCESS;
236236
}
237237

238-
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) {
239-
if (hProvider && !umf_ba_global_is_destroyed()) {
240-
hProvider->ops.finalize(hProvider->provider_priv);
241-
umf_ba_global_free(hProvider);
238+
umf_result_t umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) {
239+
if (umf_ba_global_is_destroyed()) {
240+
return UMF_RESULT_ERROR_UNKNOWN;
242241
}
242+
243+
if (!hProvider) {
244+
return UMF_RESULT_SUCCESS;
245+
}
246+
247+
umf_result_t ret = hProvider->ops.finalize(hProvider->provider_priv);
248+
umf_ba_global_free(hProvider);
249+
return ret;
243250
}
244251

245252
static void

src/memspace.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -130,14 +130,15 @@ umf_result_t umfMemspaceNew(umf_memspace_handle_t *hMemspace) {
130130
return UMF_RESULT_SUCCESS;
131131
}
132132

133-
void umfMemspaceDestroy(umf_memspace_handle_t memspace) {
133+
umf_result_t umfMemspaceDestroy(umf_memspace_handle_t memspace) {
134134
assert(memspace);
135135
for (size_t i = 0; i < memspace->size; i++) {
136136
umfMemtargetDestroy(memspace->nodes[i]);
137137
}
138138

139139
umf_ba_global_free(memspace->nodes);
140140
umf_ba_global_free(memspace);
141+
return UMF_RESULT_SUCCESS;
141142
}
142143

143144
umf_result_t umfMemspaceClone(umf_const_memspace_handle_t hMemspace,

src/pool/pool_disjoint.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,9 @@ umf_result_t disjoint_pool_get_last_allocation_error(void *pool) {
995995
}
996996

997997
// Define destructor for use with unique_ptr
998-
void disjoint_pool_finalize(void *pool) {
998+
umf_result_t disjoint_pool_finalize(void *pool) {
999999
disjoint_pool_t *hPool = (disjoint_pool_t *)pool;
1000-
1000+
umf_result_t ret = UMF_RESULT_SUCCESS;
10011001
if (hPool->params.pool_trace > 1) {
10021002
disjoint_pool_print_stats(hPool);
10031003
}
@@ -1008,10 +1008,15 @@ void disjoint_pool_finalize(void *pool) {
10081008

10091009
VALGRIND_DO_DESTROY_MEMPOOL(hPool);
10101010

1011-
umfDisjointPoolSharedLimitsDestroy(hPool->default_shared_limits);
1011+
if (umfDisjointPoolSharedLimitsDestroy(hPool->default_shared_limits) !=
1012+
UMF_RESULT_SUCCESS) {
1013+
ret = UMF_RESULT_ERROR_UNKNOWN;
1014+
LOG_ERR("umfDisjointPoolSharedLimitsDestroy failed");
1015+
}
10121016
critnib_delete(hPool->known_slabs);
10131017

10141018
umf_ba_global_free(hPool);
1019+
return ret;
10151020
}
10161021

10171022
const char *disjoint_pool_get_name(void *pool) {
@@ -1053,9 +1058,10 @@ umfDisjointPoolSharedLimitsCreate(size_t max_size) {
10531058
return ptr;
10541059
}
10551060

1056-
void umfDisjointPoolSharedLimitsDestroy(
1057-
umf_disjoint_pool_shared_limits_t *limits) {
1061+
umf_result_t
1062+
umfDisjointPoolSharedLimitsDestroy(umf_disjoint_pool_shared_limits_t *limits) {
10581063
umf_ba_global_free(limits);
1064+
return UMF_RESULT_SUCCESS;
10591065
}
10601066

10611067
umf_result_t

0 commit comments

Comments
 (0)