free(): invalid pointer:

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cyron

    free(): invalid pointer:

    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

  • gw7rib@aol.com

    #2
    Re: free(): invalid pointer:

    On 30 Sep, 21:03, Cyron <mdigit...@yaho o.comwrote:
    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?

    Comment

    • Flash Gordon

      #3
      Re: free(): invalid pointer:

      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

      Comment

      • Richard Tobin

        #4
        Re: free(): invalid pointer:

        In article <1191182600.392 335.16830@50g20 00hsm.googlegro ups.com>,
        Cyron <mdigitale@yaho o.comwrote:
        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
        --
        "Considerat ion shall be given to the need for as many as 32 characters
        in some alphabets" - X3.4, 1963.

        Comment

        Working...