what does double free or corruption (!prev): mean? Thank u~

X

xiao

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
*fp)
{

int i;

for(i=0; i<Rows; i++){
fwrite(Array, sizeof(short int),Columns, fp);
}
fclose(fp);
}

And tcumulus is defined as : short **tcumulus
 
F

fjblurt

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

Odds are that you've written past the end of an array allocated with
malloc(). Or possibly called free() twice on the same pointer.

You might try using something like ElectricFence to find the bug.
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
*fp)
{

int i;

for(i=0; i<Rows; i++){
fwrite(Array, sizeof(short int),Columns, fp);
}
fclose(fp);

}

And tcumulus is defined as : short **tcumulus


Is it possible that this is being called on a file that's already
closed? It's a little odd for a function to close a file which it
didn't open, so there could be a bug lurking.

Otherwise this looks fine, so the bug could be somewhere else in your
code. It is common for malloc() errors to go undetected until much
later in the program's execution.
 
X

xiao

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

Odds are that you've written past the end of an array allocated with
malloc(). Or possibly called free() twice on the same pointer.

You might try using something like ElectricFence to find the bug.


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
*fp)
{
for(i=0; i<Rows; i++){
fwrite(Array, sizeof(short int),Columns, fp);
}
fclose(fp);

And tcumulus is defined as : short **tcumulus


Is it possible that this is being called on a file that's already
closed? It's a little odd for a function to close a file which it
didn't open, so there could be a bug lurking.

Otherwise this looks fine, so the bug could be somewhere else in your
code. It is common for malloc() errors to go undetected until much
later in the program's execution.


Thank u~ Actually I called the function Write2DArrayInt for 10 times
and it was killed at the second one ....:(
 
B

Barry Schwarz

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
*fp)
{

int i;

for(i=0; i<Rows; i++){
fwrite(Array, sizeof(short int),Columns, fp);
}
fclose(fp);
}

And tcumulus is defined as : short **tcumulus


The two common reasons for that error message are 1) passing the same
address to free twice and 2) overrunning an allocated area before
passing its address to free.

Chances are you do one or the other in the code you haven't shown us.
You need to provide a complete, compilable, and preferably short
example that demonstrates the undesirable behavior.
 
X

xiao

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
*fp)
{
for(i=0; i<Rows; i++){
fwrite(Array, sizeof(short int),Columns, fp);
}
fclose(fp);
}

And tcumulus is defined as : short **tcumulus

The two common reasons for that error message are 1) passing the same
address to free twice and 2) overrunning an allocated area before
passing its address to free.

Chances are you do one or the other in the code you haven't shown us.
You need to provide a complete, compilable, and preferably short
example that demonstrates the undesirable behavior.

hm....i think i have figure it out ,because i closed the file at the
end of the function, then , I call the function again. SO I deleted
this line in the function : fclose(fp); and then, it works. DO u
think that is the reason?
 
D

Default User

xiao said:
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 *fp)
{
for(i=0; i<Rows; i++){
fwrite(Array, sizeof(short int),Columns, fp);
}
fclose(fp);
}

And tcumulus is defined as : short **tcumulus

The two common reasons for that error message are 1) passing the
same address to free twice and 2) overrunning an allocated area
before passing its address to free.

Chances are you do one or the other in the code you haven't shown
us. You need to provide a complete, compilable, and preferably
short example that demonstrates the undesirable behavior.

hm....i think i have figure it out ,because i closed the file at the
end of the function, then , I call the function again. SO I deleted
this line in the function : fclose(fp); and then, it works. DO u
think that is the reason?


Did you open the file again before calling the function the second time?


This is why you should provide a COMPLETE minimal program instead of
snippets.




Brian
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top