I am having some problems with the xilfatfs library for reading and writing files on a compact flash through a sysace device. Opening, reading, writing and closing files seems to be working fine but the function ''sysace_readdir'' used for reading the content of a directory seems to leak memory. After invoking ''sysace_readdir'' a number of times any subsequent calls to sysace_fopen() fails (ie. returns 0 even though the file does exist).
Internally, the xilfatfs library uses an array of ''WorkingDirectory'' for dealing with paths. This array is given in xilfatfs_alloc.c:
static WorkingDirectory wd_buf[MAXWD];
The MAXWD is defined as MAXFILES * 10. The entries in the array are used by library for manipulating and navigating paths. Access to the array is governed by the ''malloc_wd'' and ''free_wd'' functions. My investigations, thus far, shows that ''sysace_readdir()'' allocates one more ''WorkingDirectory'' than it frees which eventually leads to failure. To test this I added some code to the ''malloc_wd'' and ''free_wd'' functions in the ''xilfatfs_alloc.c'' file: