Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what does double free or corruption (!prev): mean? Thank u~

Reply
Thread Tools

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

 
 
xiao
Guest
Posts: n/a
 
      08-08-2008
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[i], sizeof(short int),Columns, fp);
}
fclose(fp);
}

And tcumulus is defined as : short **tcumulus
 
Reply With Quote
 
 
 
 
fjblurt@yahoo.com
Guest
Posts: n/a
 
      08-08-2008
On Aug 7, 6:22 pm, xiao <(E-Mail Removed)> wrote:
> 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[i], 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.
 
Reply With Quote
 
 
 
 
xiao
Guest
Posts: n/a
 
      08-08-2008
On Aug 7, 8:56 pm, (E-Mail Removed) wrote:
> On Aug 7, 6:22 pm, xiao <(E-Mail Removed)> wrote:
>
> > 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[i], 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 ....
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      08-08-2008
On Thu, 7 Aug 2008 18:22:51 -0700 (PDT), xiao <(E-Mail Removed)>
wrote:

>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[i], 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.

--
Remove del for email
 
Reply With Quote
 
xiao
Guest
Posts: n/a
 
      08-08-2008
On Aug 7, 9:39 pm, Barry Schwarz <(E-Mail Removed)> wrote:
> On Thu, 7 Aug 2008 18:22:51 -0700 (PDT), xiao <(E-Mail Removed)>
> wrote:
>
>
>
> >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[i], 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.
>
> --
> Remove del for email

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?

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      08-08-2008
xiao wrote:

> On Aug 7, 9:39 pm, Barry Schwarz <(E-Mail Removed)> wrote:
> > On Thu, 7 Aug 2008 18:22:51 -0700 (PDT), xiao
> > <(E-Mail Removed)> wrote:
> >
> >
> >
> > > 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[i], 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.
> >
> > --
> > Remove del for email

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/kolab/bin/python: double free or corruption (fasttop) aspineux Python 2 12-29-2008 06:15 AM
glibc detected: double free or corruption chuan C++ 2 11-15-2008 11:45 PM
RE: glibc detected double free or corruption Delaney, Timothy (Tim) Python 0 12-20-2006 11:39 PM
glibc detected double free or corruption Grant Edwards Python 0 12-20-2006 10:30 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM



Advertisments