View Single Post

  #2 (permalink)  
Old 05-25-2005, 08:17 PM
rockdalinux's Avatar
rockdalinux rockdalinux is offline
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Pointers that point to invalid addresses is called dangling pointers.

Some Examples that causes dangling pointers:
  • Casting arbitrary integers to pointers
    Adjusting pointers beyond the bounds of arrays
    Deallocating storage that one or more pointers still reference

C code/example of dangling pointers:
Code:
somefunc(){
x=(int *)malloc(sizeof(int));
...
free(x);
return (x); /* x is dangling pointer */
}
To avoid dangling pointers always assign NULL in C after freeing memory:
Code:
...
free(x);
x=NULL;
....
Reply With Quote