MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / PREFIX(free)

Function PREFIX(free)

Kernel/src/liballoc/liballoc.c:547–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

545}
546
547void PREFIX(free)(void *ptr)
548{
549 struct liballoc_minor *min;
550 struct liballoc_major *maj;
551
552 if (ptr == NULL)
553 {
554 l_warningCount += 1;
555#if defined DEBUG || defined INFO
556 FLUSH();
557#endif
558 return;
559 }
560
561 UNALIGN(ptr);
562
563 liballoc_lock(); // lockit
564
565
566 min = (struct liballoc_minor*)((uintptr_t)ptr - sizeof(struct liballoc_minor));
567
568
569 if (min->magic != LIBALLOC_MAGIC)
570 {
571 l_errorCount += 1;
572
573 // Check for overrun errors. For all bytes of LIBALLOC_MAGIC
574 if (
575 ((min->magic & 0xFFFFFF) == (LIBALLOC_MAGIC & 0xFFFFFF)) ||
576 ((min->magic & 0xFFFF) == (LIBALLOC_MAGIC & 0xFFFF)) ||
577 ((min->magic & 0xFF) == (LIBALLOC_MAGIC & 0xFF))
578 )
579 {
580 l_possibleOverruns += 1;
581#if defined DEBUG || defined INFO
582 assert(!"liballoc: ERROR: Possible 1-3 byte overrun\n");
583 halt();
584 FLUSH();
585#endif
586 }
587
588
589 if (min->magic == LIBALLOC_DEAD)
590 {
591#if defined DEBUG || defined INFO
592 assert(!"liballoc: ERROR: multiple PREFIX(free)() attempt \n");
593 halt();
594 FLUSH();
595#endif
596 }
597 else
598 {
599#if defined DEBUG || defined INFO
600 assert(!"liballoc: ERROR: Bad PREFIX(free)( %x ) \n");
601 halt();
602 FLUSH();
603#endif
604 }

Callers

nothing calls this directly

Calls 3

liballoc_lockFunction · 0.85
liballoc_unlockFunction · 0.85
liballoc_freeFunction · 0.85

Tested by

no test coverage detected