7
7
*
8
8
*/
9
9
10
- #include "memory_pool_internal.h"
11
- #include "memory_provider_internal.h"
12
- #include "provider_tracking.h"
10
+ #include <assert.h>
11
+ #include <stdlib.h>
13
12
14
13
#include <umf/memory_pool.h>
15
14
16
- #include <assert.h>
17
- #include <stdlib.h>
15
+ #include "base_alloc_global.h"
16
+ #include "memory_pool_internal.h"
17
+ #include "memory_provider_internal.h"
18
+ #include "provider_tracking.h"
18
19
19
20
umf_result_t umfPoolCreateInternal (const umf_memory_pool_ops_t * ops ,
20
21
umf_memory_provider_handle_t provider ,
@@ -25,7 +26,12 @@ umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
25
26
}
26
27
27
28
umf_result_t ret = UMF_RESULT_SUCCESS ;
28
- umf_memory_pool_handle_t pool = malloc (sizeof (umf_memory_pool_t ));
29
+ umf_ba_pool_t * base_allocator = umf_ba_get_pool (sizeof (umf_memory_pool_t ));
30
+ if (!base_allocator ) {
31
+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
32
+ }
33
+
34
+ umf_memory_pool_handle_t pool = umf_ba_alloc (base_allocator );
29
35
if (!pool ) {
30
36
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
31
37
}
@@ -37,6 +43,8 @@ umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
37
43
if (ret != UMF_RESULT_SUCCESS ) {
38
44
goto err_provider_create ;
39
45
}
46
+
47
+ pool -> base_allocator = base_allocator ;
40
48
pool -> own_provider = false;
41
49
42
50
pool -> ops = * ops ;
@@ -51,8 +59,7 @@ umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
51
59
err_pool_init :
52
60
umfMemoryProviderDestroy (pool -> provider );
53
61
err_provider_create :
54
- free (pool );
55
-
62
+ umf_ba_free (base_allocator , pool );
56
63
return ret ;
57
64
}
58
65
@@ -66,7 +73,8 @@ void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
66
73
}
67
74
// Destroy tracking provider.
68
75
umfMemoryProviderDestroy (hPool -> provider );
69
- free (hPool );
76
+ // TODO: this free keeps memory in base allocator, so it can lead to OOM in some scenarios (it should be optimized)
77
+ umf_ba_free (hPool -> base_allocator , hPool );
70
78
}
71
79
72
80
umf_result_t umfFree (void * ptr ) {
0 commit comments