MCPcopy Create free account
hub / github.com/coreboot/coreboot / free

Function free

payloads/libpayload/libc/malloc.c:256–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void free(void *ptr)
257{
258 hdrtype_t hdr;
259 struct memory_type *type = heap;
260
261 /* No action occurs on NULL. */
262 if (ptr == NULL)
263 return;
264
265 /* Sanity check. */
266 if (ptr < type->start || ptr >= type->end) {
267 type = dma;
268 if (ptr < type->start || ptr >= type->end)
269 return;
270 }
271
272 if (free_aligned(ptr, type)) return;
273
274 ptr -= HDRSIZE;
275 hdr = *((hdrtype_t *) ptr);
276
277 /* Not our header (we're probably poisoned). */
278 if (!HAS_MAGIC(hdr))
279 return;
280
281 /* Double free. */
282 if (hdr & FLAG_FREE)
283 return;
284
285 *((hdrtype_t *) ptr) = FREE_BLOCK(SIZE(hdr));
286 _consolidate(type);
287}
288
289void *malloc(size_t size)
290{

Callers 15

reallocFunction · 0.70
allocate_regionFunction · 0.70
try_free_regionFunction · 0.70
pci_free_devFunction · 0.50
get_option_as_stringFunction · 0.50
set_option_from_stringFunction · 0.50
cbmem_console_snapshotFunction · 0.50
dwc2_halt_epFunction · 0.50
complete_ep_transferFunction · 0.50
dwc2_force_shutdownFunction · 0.50
dwc2_freeFunction · 0.50
dwc2_udc_initFunction · 0.50

Calls 2

free_alignedFunction · 0.85
_consolidateFunction · 0.85

Tested by 1

teardown_cbfs_testFunction · 0.40