[gmx-developers] Using xdrfile_close in libxdrfile

Ran Friedman r.friedman at bioc.uzh.ch
Fri Mar 27 10:36:13 CET 2009


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.

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.


-- 
------------------------------------------------------
Ran Friedman
Postdoctoral Fellow
Computational Structural Biology Group (A. Caflisch)
Department of Biochemistry
University of Zurich
Winterthurerstrasse 190
CH-8057 Zurich, Switzerland
Tel. +41-44-6355593
Email: r.friedman at bioc.unizh.ch
Skype: ran.friedman
------------------------------------------------------




More information about the gromacs.org_gmx-developers mailing list