Thread: What does this error mean? double free or corruption

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    7

    What does this error mean? double free or corruption

    Hey ~ everyone~
    What does this error mean?
    *** glibc detected *** double free or corruption (!prev):

    It occurs when i tried to write to a file like this :

    Code:
    Write2DArrayInt(tcumulus, ncolumns,nrows, out);
    
    Write2DArrayInt is a function like this:
    
    void Write2DArrayInt(short int **Array, int Columns, int Rows, FILE
    *fp)
    {
    
    int i;
    
    for(i=0; i<Rows; i++){
    fwrite(Array[i], sizeof(short int),Columns, fp);
    }
    fclose(fp);
    
    }

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You stomped on memory somewhere, or freed something twice. Without seeing a complete program it's hard to say what, exactly, the problem is. Since you appear to be on Linux, I'd recommend Valgrind. It's a great debugger that will tell you all sorts of places you made a mistake, even if your program doesn't crash at that point. It should help narrow down problems. gdb, of course, is also a useful tool.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    BTW, where is your file "opened" for writing?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by kcpilot View Post
    BTW, where is your file "opened" for writing?
    Yes, it is traditional to put the OPEN and CLOSE in matched pairs, so either the function both opens and closes the file, or it's part of the upper layer to open AND close the file. There are exceptions, but this doesn't look like one of those exception cases.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double free or corruption (out)
    By Mouser58907 in forum C Programming
    Replies: 5
    Last Post: 02-25-2009, 12:20 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  4. Replies: 7
    Last Post: 11-26-2007, 01:11 PM
  5. Malloc - Free giving double free or corruption error
    By andrew.bolster in forum C Programming
    Replies: 2
    Last Post: 11-02-2007, 06:22 AM