[gmx-developers] Using xdrfile_close in libxdrfile

David van der Spoel spoel at xray.bmc.uu.se
Fri Mar 27 11:43:23 CET 2009


Ran Friedman wrote:
> Dear Developers,
> 
> I've downloaded and installed libxdrfile from the CVS and started to write a C code that uses some of the functions.
> 
> Basically, the code goes frame by frame over an xtc file to get the number of frames etc., then close the xtc file.
> 

Hi Ran,

thanks for testing this!
I fixed this code, by returning en exdrENDOFFILE instead, so please test 
for this. I've also updated the test such that it does not assume there 
are a certain number of frames in the file.

Please update your cvs and try again.


> I've started testing it on an xtc file with a single frame. I have the following line:
> 
> [code]
> result=read_xtc(xtc,natom,&step,&time,box,x,&precision);
> [end]
> 
> Which returns exdrOK after the first readout and exdrINT after the second. 
> Then when I try to close the file I get the following error:
> *** glibc detected *** munmap_chunk(): invalid pointer: 0x0000000000634700 ***
> 
> Which occurs in the xdrfile_close function (xdrfile.c):
> [code, lines 244 - 263 ]
> int
> xdrfile_close(XDRFILE *xfp)
> {
>         int ret=exdrCLOSE;
>         if(xfp) 
>     {
>                 /* flush and destroy XDR stream */
>                 if(xfp->xdr)
>                         xdr_destroy((XDR *)(xfp->xdr));
>                 free(xfp->xdr);
>                 /* close the file */
>                 ret=fclose(xfp->fp);
>                 if(xfp->buf1size)
>                         free(xfp->buf1); /* <== free fails here */
>                 if(xfp->buf2size)
>                         free(xfp->buf2);
>                 free(xfp);
>         }
>         return ret; /* return 0 if ok */
> }
> [end]
> 
> the call for "free" fails for releasing the memory from xfp->buf1 (line 257, indicated).
> 
> My system is SUSE LINUX 10.1, 64bit, gcc 4.1.0.
> Gromacs runs without any apparent problem on the same machine, and gmxcheck had
> no trouble with the xtc file.
> 
> I'd appreciate any advise - have submitted a bugzilla as well. In the test code this is not checked since the number of frames is known a priori.
> 
> Thanks,
> Ran.
> 
> 


-- 
David van der Spoel, Ph.D., Professor of Biology
Molec. Biophys. group, Dept. of Cell & Molec. Biol., Uppsala University.
Box 596, 75124 Uppsala, Sweden. Phone:	+46184714205. Fax: +4618511755.
spoel at xray.bmc.uu.se	spoel at gromacs.org   http://folding.bmc.uu.se



More information about the gromacs.org_gmx-developers mailing list