* free a malloc_elem block by adding it to the free list. If the * blocks either immediately before or immediately after newly freed block * are also free, the blocks are merged together. */
| 567 | * are also free, the blocks are merged together. |
| 568 | */ |
| 569 | struct malloc_elem * |
| 570 | malloc_elem_free(struct malloc_elem *elem) |
| 571 | { |
| 572 | void *ptr; |
| 573 | size_t data_len; |
| 574 | |
| 575 | ptr = RTE_PTR_ADD(elem, MALLOC_ELEM_HEADER_LEN); |
| 576 | data_len = elem->size - MALLOC_ELEM_OVERHEAD; |
| 577 | |
| 578 | /* |
| 579 | * Consider the element clean for the purposes of joining. |
| 580 | * If both neighbors are clean or non-existent, |
| 581 | * the joint element will be clean, |
| 582 | * which means the memory should be cleared. |
| 583 | * There is no need to clear the memory if the joint element is dirty. |
| 584 | */ |
| 585 | elem->dirty = false; |
| 586 | elem = malloc_elem_join_adjacent_free(elem); |
| 587 | |
| 588 | malloc_elem_free_list_insert(elem); |
| 589 | |
| 590 | elem->pad = 0; |
| 591 | |
| 592 | /* decrease heap's count of allocated elements */ |
| 593 | elem->heap->alloc_count--; |
| 594 | |
| 595 | #ifndef RTE_MALLOC_DEBUG |
| 596 | /* Normally clear the memory when needed. */ |
| 597 | if (!elem->dirty) |
| 598 | memset(ptr, 0, data_len); |
| 599 | #else |
| 600 | /* Always poison the memory in debug mode. */ |
| 601 | memset(ptr, MALLOC_POISON, data_len); |
| 602 | #endif |
| 603 | |
| 604 | return elem; |
| 605 | } |
| 606 | |
| 607 | /* assume all checks were already done */ |
| 608 | void |
no test coverage detected