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

  1. #1
    Registered User
    Join Date
    Jul 2008

    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 :

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

  2. #2
    Registered User
    Join Date
    Sep 2007
    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
    Euless, TX
    BTW, where is your file "opened" for writing?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    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.

    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