More segmentation faults.

Ray Van Dolson rayvd at bludgeon.org
Sun May 27 08:01:59 GMT 2001


Far from being an C expert here, so I thought I'd throw this out...

int descend(char url[]) {
	char *directories[512];
	char *tmpurl;
	int i, count;

	printf("Descending into %s\n",url);
	//
	// This portion of code will retrive a listing of directories
	//
	for (i = 0; i < 512; i++)
		directories[i] = (char *) malloc(255);
	i = directory_list(url,directories);
	// End of retrieval
	for (count = 0; count < i; count++) {
		 tmpurl = (char *) malloc(strlen(url) + \
			strlen(directories[count]) + 1);
		sprintf(tmpurl,"%s/%s",url,directories[count]);
		printf("Is %s a directory? ",tmpurl);
		if (is_directory(tmpurl) > 0) {
			if (!strstr(tmpurl,"/.") && !strstr(tmpurl,"/.."))
{
				printf("Yes\n");
				descend(tmpurl);
			}
		}
		else if (is_file(tmpurl)) {
			printf("No\n");
			printf("Inserting %s into database.\n",tmpurl);
			// insertDB(tmpurl);
		} else
			printf("No\n");
	}
	for (i = 0; i < 512; i++)
		free(directories[i]);
}

This is a recursive function, bsaically I'm trying to map out a computer
and it's shared contents.  For some reason when I start into a second
level directory it segmentation faults.  I'm sure this has something to do
with my use of free() and malloc(), any pointers on a better way to
achieve this?





More information about the samba-technical mailing list