Last active
September 29, 2015 08:36
-
-
Save bruce30262/378b63490cb3fd318431 to your computer and use it in GitHub Desktop.
malloc.c -- unlink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define unlink(AV, P, BK, FD) { | |
FD = P->fd; | |
BK = P->bk; | |
if (__builtin_expect (FD->bk != P || BK->fd != P, 0)) | |
malloc_printerr (check_action, "corrupted double-linked list", P, AV); | |
else { | |
FD->bk = BK; | |
BK->fd = FD; | |
if (!in_smallbin_range (P->size) | |
&& __builtin_expect (P->fd_nextsize != NULL, 0)) { | |
if (__builtin_expect (P->fd_nextsize->bk_nextsize != P, 0) | |
|| __builtin_expect (P->bk_nextsize->fd_nextsize != P, 0)) | |
malloc_printerr (check_action, | |
"corrupted double-linked list (not small)", | |
P, AV); | |
if (FD->fd_nextsize == NULL) { | |
if (P->fd_nextsize == P) | |
FD->fd_nextsize = FD->bk_nextsize = FD; | |
else { | |
FD->fd_nextsize = P->fd_nextsize; | |
FD->bk_nextsize = P->bk_nextsize; | |
P->fd_nextsize->bk_nextsize = FD; | |
P->bk_nextsize->fd_nextsize = FD; | |
} | |
} else { | |
P->fd_nextsize->bk_nextsize = P->bk_nextsize; | |
P->bk_nextsize->fd_nextsize = P->fd_nextsize; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment