LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: dburbano_at_[hidden]
Date: 2003-06-26 10:25:38


May be you free a pointer that was free, for example

int * pfirst;
int * psecond;

pfirst = psecond;

free (psecond);
free (pfirst); <-- You get an error

> On Thu, 26 Jun 2003, Pak, Anne O wrote:
>
>> i use malloc to allocate memory for variable that i use to store data
>> that i eventually send out to other nodes using MPI_Send.
>>
>> if i don't call free at the end, my program works fine, but if i do,
>> (even if i call it after i complete MPI_Send), i get
>> MPI process rank 0 (n26, p22769) caught a SIGSEGV.
>>
>> for example:
>>
>> double *temp;
>> temp = (double *)malloc(3*sizeof(double));
>> for (i=0;i<3;i++)
>> temp[i]=i;
>> MPI_Send(temp,3,MPI_DOUBLE,1,tag,comm);
>> free(temp);
>>
>> is there a trick to this? do i need to call MPI_Barrier or something?
>
> That's definitely odd, and from the code snipit shown here, should not
> happen. When MPI_Send returns, the temp buffer is totally back in your
> control, so you should be able to free it.
>
> This is a typical symptom of some other kind of memory badness elsewhere
> in your code. Can you run it through a memory-checking debugger, such
> as valgrind, Purify, or bcheck? If that's not an option, you might want
> to see if someone is accidentally trying to use the temp buffer after
> you free it -- try assigning it to NULL after the free statement. Or
> assigning it to NULL *instead* of the free statement. You might want to
> try to run this inside a debugger (or attach a debugger after the
> program starts) and see exactly where the seg fault is occuring.
>
> --
> {+} Jeff Squyres
> {+} jsquyres_at_[hidden]
> {+} http://www.lam-mpi.org/
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/