Double free & heap corruption
Në shqip: Lirimi i dyfishtë
ShpjegimiSQ
Po e thirre free() dy herë për të njëjtin pointer, ose po shkrove jashtë bllokut të marrë me malloc, „prish“ strukturat e brendshme të heap-it. Programi mund të rrëzohet shumë më vonë, në një vend krejt tjetër.
EnglishEN
If you call free() twice on the same pointer, or write outside a block from malloc, you “corrupt” the heap's internal structures. The program might crash much later, somewhere completely different.
Si ta mendosh
Si t'ia kthesh çelësin e depos pronarit dy herë: herën e dytë po i jep çelësin e dikujt tjetër.
Lexoje në anglisht
Like returning the storage key to the owner twice: the second time you're handing over someone else's key.
Shembull kodic
char *p = malloc(10);
free(p);
free(p); // GABIM: double free
p = NULL; // pas free, gjithmonë NULL