Lines Matching refs:hdr
71 static void debug_header(memory_header *hdr) in debug_header() argument
79 (size_t) hdr, (size_t) hdr->prev, (size_t) hdr->next, in debug_header()
80 hdr->alloc, hdr->size); in debug_header()
82 (size_t) hdr->prev_free, (size_t) hdr->next_free); in debug_header()
86 for (i = 0; i < hdr->trace_count; i++) { in debug_header()
87 mbedtls_fprintf(stderr, "%s\n", hdr->trace[i]); in debug_header()
113 static int verify_header(memory_header *hdr) in verify_header() argument
115 if (hdr->magic1 != MAGIC1) { in verify_header()
122 if (hdr->magic2 != MAGIC2) { in verify_header()
129 if (hdr->alloc > 1) { in verify_header()
136 if (hdr->prev != NULL && hdr->prev == hdr->next) { in verify_header()
143 if (hdr->prev_free != NULL && hdr->prev_free == hdr->next_free) { in verify_header()
362 memory_header *hdr, *old = NULL; in buffer_alloc_free() local
378 hdr = (memory_header *) p; in buffer_alloc_free()
380 if (verify_header(hdr) != 0) { in buffer_alloc_free()
384 if (hdr->alloc != 1) { in buffer_alloc_free()
392 hdr->alloc = 0; in buffer_alloc_free()
396 heap.total_used -= hdr->size; in buffer_alloc_free()
400 free(hdr->trace); in buffer_alloc_free()
401 hdr->trace = NULL; in buffer_alloc_free()
402 hdr->trace_count = 0; in buffer_alloc_free()
407 if (hdr->prev != NULL && hdr->prev->alloc == 0) { in buffer_alloc_free()
411 hdr->prev->size += sizeof(memory_header) + hdr->size; in buffer_alloc_free()
412 hdr->prev->next = hdr->next; in buffer_alloc_free()
413 old = hdr; in buffer_alloc_free()
414 hdr = hdr->prev; in buffer_alloc_free()
416 if (hdr->next != NULL) { in buffer_alloc_free()
417 hdr->next->prev = hdr; in buffer_alloc_free()
425 if (hdr->next != NULL && hdr->next->alloc == 0) { in buffer_alloc_free()
429 hdr->size += sizeof(memory_header) + hdr->next->size; in buffer_alloc_free()
430 old = hdr->next; in buffer_alloc_free()
431 hdr->next = hdr->next->next; in buffer_alloc_free()
433 if (hdr->prev_free != NULL || hdr->next_free != NULL) { in buffer_alloc_free()
434 if (hdr->prev_free != NULL) { in buffer_alloc_free()
435 hdr->prev_free->next_free = hdr->next_free; in buffer_alloc_free()
437 heap.first_free = hdr->next_free; in buffer_alloc_free()
440 if (hdr->next_free != NULL) { in buffer_alloc_free()
441 hdr->next_free->prev_free = hdr->prev_free; in buffer_alloc_free()
445 hdr->prev_free = old->prev_free; in buffer_alloc_free()
446 hdr->next_free = old->next_free; in buffer_alloc_free()
448 if (hdr->prev_free != NULL) { in buffer_alloc_free()
449 hdr->prev_free->next_free = hdr; in buffer_alloc_free()
451 heap.first_free = hdr; in buffer_alloc_free()
454 if (hdr->next_free != NULL) { in buffer_alloc_free()
455 hdr->next_free->prev_free = hdr; in buffer_alloc_free()
458 if (hdr->next != NULL) { in buffer_alloc_free()
459 hdr->next->prev = hdr; in buffer_alloc_free()
469 hdr->next_free = heap.first_free; in buffer_alloc_free()
471 heap.first_free->prev_free = hdr; in buffer_alloc_free()
473 heap.first_free = hdr; in buffer_alloc_free()