free(): invalid pointer:

Discussion in 'C Programming' started by Cyron, Sep 30, 2007.

  1. Cyron

    Cyron Guest

    Hello friends,

    I'm getting a bizaare glibc error referencing free -- I malloc a
    chunk of memory and then later when I try to free it is when the
    program aborts. I've added some debug code to the source and find
    that my pointer i get from malloc matches the one that I'm calling
    free with -- and there is no possibility that have i have previously
    freed the memory because there is only 1 free call in the entire
    source (surrounded by debug printfs) so I don't know what is going on.
    Any insight?

    Thanks,
    Mike
     
    Cyron, Sep 30, 2007
    #1
    1. Advertising

  2. Cyron

    Guest

    On 30 Sep, 21:03, Cyron <> wrote:
    > Hello friends,
    >
    > I'm getting a bizaare glibc error referencing free -- I malloc a
    > chunk of memory and then later when I try to free it is when the
    > program aborts. I've added some debug code to the source and find
    > that my pointer i get from malloc matches the one that I'm calling
    > free with -- and there is no possibility that have i have previously
    > freed the memory because there is only 1 free call in the entire
    > source (surrounded by debug printfs) so I don't know what is going on.
    > Any insight?


    Are you perhaps writing to memory just outside the memory you have
    allocated?
     
    , Sep 30, 2007
    #2
    1. Advertising

  3. Cyron

    Flash Gordon Guest

    Cyron wrote, On 30/09/07 21:03:
    > I'm getting a bizaare glibc error referencing free -- I malloc a
    > chunk of memory and then later when I try to free it is when the
    > program aborts. I've added some debug code to the source and find


    <snip>

    You are probably writing beyond the end or before the start of the
    allocated space. If you can get the program down to a reasonably small
    chunk of code that shows the problem we can take a look at it.
    --
    Flash Gordon
     
    Flash Gordon, Sep 30, 2007
    #3
  4. In article <>,
    Cyron <> wrote:

    > I'm getting a bizaare glibc error referencing free -- I malloc a
    >chunk of memory and then later when I try to free it is when the
    >program aborts. I've added some debug code to the source and find
    >that my pointer i get from malloc matches the one that I'm calling
    >free with -- and there is no possibility that have i have previously
    >freed the memory because there is only 1 free call in the entire
    >source (surrounded by debug printfs) so I don't know what is going on.


    You almost certainly have some kind of out-of-bounds pointer error.
    Your first choice for finding such things, if you have one available,
    is a memory-reference-checking tool such as valgrind. From your
    reference to glibc, I assume you're using Linux, so valgrind should be
    available. I find that 90% of the time it directs me straight to the
    bug.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Sep 30, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Machado

    pointer-to-pointer (invalid lvalue in unary `&)

    Lucas Machado, Apr 3, 2004, in forum: C Programming
    Replies:
    19
    Views:
    11,024
    Irrwahn Grausewitz
    Apr 15, 2004
  2. c language

    free(): invalid pointer

    c language, Jun 14, 2006, in forum: C Programming
    Replies:
    4
    Views:
    581
    Michael Mair
    Jun 14, 2006
  3. Replies:
    17
    Views:
    532
    Chris Dollin
    Feb 26, 2007
  4. george
    Replies:
    0
    Views:
    1,146
    george
    Aug 29, 2008
  5. mohammed_a_o
    Replies:
    0
    Views:
    287
    mohammed_a_o
    Nov 30, 2010
Loading...

Share This Page