File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,28 @@ void *umf_ba_alloc(umf_ba_pool_t *pool) {
196
196
return chunk ;
197
197
}
198
198
199
+ #ifndef NDEBUG
200
+ // Checks if given pointer belongs to the pool. Should be called
201
+ // under the lock
202
+ static int pool_contains_pointer (umf_ba_pool_t * pool , void * ptr ) {
203
+ char * cptr = (char * )ptr ;
204
+ if (cptr >= pool -> data && cptr < ((char * )(pool )) + pool -> metadata .pool_size ) {
205
+ return 1 ;
206
+ }
207
+
208
+ umf_ba_next_pool_t * next_pool = pool -> next_pool ;
209
+ while (next_pool ) {
210
+ if (cptr >= next_pool -> data &&
211
+ cptr < ((char * )(next_pool )) + pool -> metadata .pool_size ) {
212
+ return 1 ;
213
+ }
214
+ next_pool = next_pool -> next_pool ;
215
+ }
216
+
217
+ return 0 ;
218
+ }
219
+ #endif
220
+
199
221
void umf_ba_free (umf_ba_pool_t * pool , void * ptr ) {
200
222
if (ptr == NULL ) {
201
223
return ;
@@ -204,6 +226,7 @@ void umf_ba_free(umf_ba_pool_t *pool, void *ptr) {
204
226
umf_ba_chunk_t * chunk = (umf_ba_chunk_t * )ptr ;
205
227
206
228
util_mutex_lock (& pool -> metadata .free_lock );
229
+ assert (pool_contains_pointer (pool , ptr ));
207
230
chunk -> next = pool -> metadata .free_list ;
208
231
pool -> metadata .free_list = chunk ;
209
232
#ifndef NDEBUG
You can’t perform that action at this time.
0 commit comments