1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

free(): invalid pointer 0x842e3344,problem with free

Discussion in 'C' started by raklo, Feb 2, 2007.

  1. raklo

    raklo New Member

    Joined:
    Feb 2, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i've written a code that simply forks a process,executes a command thru
    execve() and exits,wherein i've used
    char *fildes;
    allocated a char sting to fildes by
    char *itoa(int x)
    filedes=itoa(3);

    and then execve(args[0],args,env);
    wherein on of the contents of args[0] is fildes.

    now when i do
    free(fildes);

    I get error
    *** glibc detected *** free(): invalid pointer: 0x080a6bfe ***
    Aborted.

    can u tell wotz prob with the code.
    ANY INPUT IS APPRECIATED
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Looks like fildes is not a valid pointer.
     
  3. raklo

    raklo New Member

    Joined:
    Feb 2, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    wotz the solution for it???
    the thing is that i've used this program inthe initrd image ,though this error occurs
    everytime but my system does boot.but the main problem is once in every 3-4 boots the system panics, and i believe this is the cause of it.

    so wot can be the solution???
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Try freeing it only when its valid and assign a null by default so you know if its not null you free it.
     
  5. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Assigning a value to a pointer is NOT allocating it. You can only free a pointer that your have gotten from malloc or its variants.
     

Share This Page