Google
  Web www.spinics.net

need help with scandir...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi All,
I'm using the scandir(3) in a program. This is in a void routing that
creates the struct "struct dirent **filelist = {0};"
However, this often times reports an invalid memory access when I
repeat the routine.
It looks pretty much the same as in the man pages:

void my_dir scan()
{
   .......
   struct dirent **filelist = {0};
   .....

   filecount = scandir("/tmp/usbstick", &filelist, 0, alphasort);
   .....

   for(i = 0; i < filecount; i++)
   {
       .....
    free(filelist[i]);
    }
free(filelist);
}

If I run my_dir_scan()  I may get an invalid memory (seg fault) at the
scandir line or it may occur after I ran it two or three times.

Does anyone know why this occurs??

Thanks.

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php

[Site Home]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux ARM Kernel]     [Linux MIPS]     [ECOS]     [Tools]     [DDR & Rambus]     [Monitors]

Powered by Linux