c - how we can solve double free corruption -


i have 2 pointer have same address. if free one. should not use 2nd one. because free memory might using in next code. if free 1 cant free second .plz give me solution example.

the idea when free 1 of 2 pointers, set both null. also, programming practice test pointer set before using it.

 char *ptr1 = malloc(80);   char *ptr2 = ptr1;   free(ptr2);  ptr1 = ptr2 = null;  // other stuff happens here, , if code doesn't "know"  // ptr1 set correctly then...  if (ptr1 != null)  {  // etc.   } 

hope asking, , hope helps. luck future coding endeavors.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -