LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-29-2010, 02:13 PM   #1
vbnandu86
LQ Newbie
 
Registered: Aug 2006
Posts: 16

Rep: Reputation: 0
Segmentation fault when the recursing through a large file structure


Hi all ,
The following code tries traverse the directories with the starting directory given in *directoryPath.
If the directory in *directoryPath is just a directory ending with one or 2 sub-directories,it works fine.However if directoryPath = "/".There is seg.fault.I have attached a part of the output and the backtrace at the end.
Can u tell me what could be the problem ?

Code:
void walker(char *directoryPath){
	struct dirent **namelist ={0};
	int numOfEntries=0, i=0;
	char *temp; 
	int file_select();
	printf("In %s\n",directoryPath); 
	numOfEntries = scandir(directoryPath, &namelist, file_select,NULL);
	printf("The Number of entries in %s are %d\n",directoryPath,numOfEntries);
	for (i=1;i<numOfEntries+1;++i){
		 printf("%s  \n",namelist[i-1]->d_name);	 
	
	}
	for (i=1;i<numOfEntries+1;++i){
			temp = (char*)calloc(((size_t)strlen(directoryPath)+strlen(namelist[i-1]->d_name)+1),sizeof(char));
			strcat(temp,directoryPath);
			strcat(temp,"/");
			strcat(temp,namelist[i-1]->d_name);
			printf("===============================================================================================\n");
			walker(temp);
			free(temp);
	}
}
Part of the OutPut and Backtrace in GDB
Code:
......
In //dev/.udev/links/input\x2fby-path\x2fplatform-i8042-serio-1-event-mouse
The Number of entries in //dev/.udev/links/input\x2fby-path\x2fplatform-i8042-serio-1-event-mouse are 0
===============================================================================================
In //dev/.udev/links/input\x2fby-path\x2fplatform-i8042-serio-1-mouse
The Number of entries in //dev/.udev/links/input\x2fby-path\x2fplatform-i8042-serio-1-mouse are 0
===============================================================================================
In //dev/.udev/links/snd\x2fby-path\x2fpci-0000:00:1b.0

Program received signal SIGSEGV, Segmentation fault.
0x0019983e in ?? () from /lib/tls/i686/cmov/libc.so.6
(gdb) backtrace
#0  0x0019983e in ?? () from /lib/tls/i686/cmov/libc.so.6
#1  0x0019bafd in ?? () from /lib/tls/i686/cmov/libc.so.6
#2  0x0019df9c in malloc () from /lib/tls/i686/cmov/libc.so.6
#3  0x001c16e9 in ?? () from /lib/tls/i686/cmov/libc.so.6
#4  0x001c180a in opendir () from /lib/tls/i686/cmov/libc.so.6
#5  0x001c1bd2 in scandir () from /lib/tls/i686/cmov/libc.so.6
#6  0x080485a7 in walker (directoryPath=0x804c2c8 "//dev/.udev/links/snd\\x2fby-path\\x2fpci-0000:00:1b.0") at TraverseDirectory.c:14
#7  0x080486ad in walker (directoryPath=0x804b1c0 "//dev/.udev/links") at TraverseDirectory.c:26
#8  0x080486ad in walker (directoryPath=0x804b018 "//dev/.udev") at TraverseDirectory.c:26
#9  0x080486ad in walker (directoryPath=0x804b008 "//dev") at TraverseDirectory.c:26
#10 0x080486ad in walker (directoryPath=0x8048842 "/") at TraverseDirectory.c:26
#11 0x08048741 in main () at TraverseDirectory.c:45
 
Old 07-30-2010, 03:53 AM   #2
everest40
Member
 
Registered: Jul 2008
Distribution: Ubuntu $LATESTVERSION
Posts: 168

Rep: Reputation: 68
Do you have read permission for the folder //dev/.udev/links/snd\x2fby-path\x2fpci-0000:00:1b.0?
 
  


Reply

Tags
segmentation fault, traversal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Large file structure badjuice420 Linux - Server 1 08-31-2009 06:15 PM
Segmentation fault (core dumped) when installing bin file ToniMe Linux - Software 6 10-02-2007 04:39 AM
Fortran Code with Large arrays statically allocated -> segmentation fault eiffel Linux - Kernel 2 07-19-2006 10:14 AM
Segmentation fault on writing 1022'nd file (C++) joejk2 Programming 2 04-03-2006 11:58 AM
Segmentation fault after declaring a large array. oulevon Programming 6 11-08-2005 02:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration