@@ -186,14 +186,24 @@ void *umf_ba_global_aligned_alloc(size_t size, size_t alignment) {
186186
187187 int ac_index = size_to_idx (size );
188188 if (ac_index >= NUM_ALLOCATION_CLASSES ) {
189- return add_metadata_and_align (ba_os_alloc (size ), size , alignment );
189+ void * ptr = ba_os_alloc (size );
190+ if (!ptr ) {
191+ return NULL ;
192+ }
193+ VALGRIND_DO_MALLOCLIKE_BLOCK (ptr , size , 0 , 0 );
194+ return add_metadata_and_align (ptr , size , alignment );
190195 }
191196
192197 if (!BASE_ALLOC .ac [ac_index ]) {
193198 // if creating ac failed, fall back to os allocation
194199 LOG_WARN ("base_alloc: allocation class not created. Falling "
195200 "back to OS memory allocation." );
196- return add_metadata_and_align (ba_os_alloc (size ), size , alignment );
201+ void * ptr = ba_os_alloc (size );
202+ if (!ptr ) {
203+ return NULL ;
204+ }
205+ VALGRIND_DO_MALLOCLIKE_BLOCK (ptr , size , 0 , 0 );
206+ return add_metadata_and_align (ptr , size , alignment );
197207 }
198208
199209 return add_metadata_and_align (umf_ba_alloc (BASE_ALLOC .ac [ac_index ]), size ,
@@ -220,12 +230,14 @@ void umf_ba_global_free(void *ptr) {
220230
221231 int ac_index = size_to_idx (total_size );
222232 if (ac_index >= NUM_ALLOCATION_CLASSES ) {
233+ VALGRIND_DO_FREELIKE_BLOCK (ptr , 0 );
223234 ba_os_free (ptr , total_size );
224235 return ;
225236 }
226237
227238 if (!BASE_ALLOC .ac [ac_index ]) {
228239 // if creating ac failed, memory must have been allocated by os
240+ VALGRIND_DO_FREELIKE_BLOCK (ptr , 0 );
229241 ba_os_free (ptr , total_size );
230242 return ;
231243 }
0 commit comments