LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   free pointer (https://www.linuxquestions.org/questions/programming-9/free-pointer-293826/)

os2 02-23-2005 07:58 AM

free pointer
 
hi

habitually, i free when i do a malloc...
but i see sometime on the web some people who free pointer created without maloc

Code:

void checkIO()
{
        struct conn *conn_ptr = conns;

        while(conn_ptr != NULL) {
                if(fdIsReadable(conn_ptr->fd))
                        doIO(conn_ptr);
                conn_ptr = conn_ptr->next;
        }
}

here some people will do after the while:

Code:

free(conn_ptr );
thanks

itsme86 02-23-2005 09:07 AM

Perhaps conns is allocated somewhere. It's the same as doing like this:
Code:

{
  int *a = malloc(sizeof(int));
  int *b = a;

  free(b);
}

b and a both point to the same memory so you can pass either one to free().


All times are GMT -5. The time now is 08:47 PM.