File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,29 @@ void *umf_ba_alloc(umf_ba_pool_t *pool) {
196196 return chunk ;
197197}
198198
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 &&
205+ cptr < ((char * )(pool )) + pool -> metadata .pool_size ) {
206+ return 1 ;
207+ }
208+
209+ umf_ba_next_pool_t * next_pool = pool -> next_pool ;
210+ while (next_pool ) {
211+ if (cptr >= next_pool -> data &&
212+ cptr < ((char * )(next_pool )) + pool -> metadata .pool_size ) {
213+ return 1 ;
214+ }
215+ next_pool = next_pool -> next_pool ;
216+ }
217+
218+ return 0 ;
219+ }
220+ #endif
221+
199222void umf_ba_free (umf_ba_pool_t * pool , void * ptr ) {
200223 if (ptr == NULL ) {
201224 return ;
@@ -204,6 +227,7 @@ void umf_ba_free(umf_ba_pool_t *pool, void *ptr) {
204227 umf_ba_chunk_t * chunk = (umf_ba_chunk_t * )ptr ;
205228
206229 util_mutex_lock (& pool -> metadata .free_lock );
230+ assert (pool_contains_pointer (pool , ptr ));
207231 chunk -> next = pool -> metadata .free_list ;
208232 pool -> metadata .free_list = chunk ;
209233#ifndef NDEBUG
You can’t perform that action at this time.
0 commit comments