I have found the answer to my question myself:)
So what I didn't understand was how the glibc could differentiate between a Segfault and a corrupted double-linked list, because according to my understanding, from perspective of glibc they should look like the same thing.
Because if I implement a double-linked list inside my program, how could the glibc possibly know that this is a double-linked list, instead of any other struct? It probably can't, so thats why i was confused.
Now I've looked at malloc/malloc.c inside the glibc's code, and I see the following:
1543 /* Take a chunk off a bin list */
1544 #define unlink(P, BK, FD) {
1545 FD = P->fd;
1546 BK = P->bk;
1547 if (__builtin_expect (FD->bk != P || BK->fd != P, 0))
1548 malloc_printerr (check_action, "corrupted double-linked list", P);
1549 else {
1550 FD->bk = BK;
1551 BK->fd = FD;
So now this suddenly makes sense. The reason why glibc can know that this is a double-linked list is because the list is part of glibc itself. I've been confused because I thought glibc can somehow detect that some programming is building a double-linked list, which I wouldn't understand how that works. But if this double-linked list that it is talking about, is part of glibc itself, of course it can know it's a double-linked list.
I still don't know what has triggered this error. But at least I understand the difference between corrupted double-linked list and a Segfault, and how the glibc can know this struct is supposed to be a double-linked list:)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…