C

Dangling pointer

Në shqip: Pointer i varur

ShpjegimiSQ

Një pointer i varur tregon te memorie që është liruar ose që s'ekziston më — p.sh. pas free(), ose te një variabël lokale e një funksioni që ka mbaruar. Po e përdore, rezultati është i paparashikueshëm. Pas free(p), shkruaj p = NULL.

EnglishEN

A dangling pointer points to memory that has been freed or no longer exists — like after free(), or to a local variable of a function that has finished. Using it gives unpredictable results. After free(p), write p = NULL.

Si ta mendosh

Si adresa e një shoku që është shpërngulur: shkon te dera dhe hap një tjetër njeri — ose shtëpia s'ekziston fare.

Lexoje në anglisht

Like the address of a friend who's moved: you knock on the door and a stranger answers — or the house is gone.

Shembull kodic

int *p = malloc(sizeof(int));
free(p);
// *p = 5;   // GABIM: use after free
p = NULL;   // tani është e sigurt

Terma të lidhur