I have a ‘curl: (52) Empty reply from server’ on my terminal with ‘free(): invalid next size (normal)’ on the debugger.
The execution is fine until if(file == NULL) check in transfer() function. Here is a print screen of file details.
void transfer(const char* path, const char* type)
{
// ensure path is readable
if (access(path, R_OK) == -1)
{
error(403);
return;
}
// open file
FILE* file = fopen(path, "r");
if (file == NULL)
{
printf("Reaching here 7\n");
error(500);
return;
}
The printf statement is not executed. But the error(500) statement is highlighted, after which process stops with exit code 0 and the following:
Child terminated with signal = 0x6 (SIGABRT)
My program is passing check50 except for this scenario which I was testing out:
:( Requesting /test/ outputs /test/index.html \ expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..."
Please let me know what could be causing the issue. Thanks!
Here is my indexes function():
char* indexes(const char* path)
{
DIR *directory = opendir(path);
if(directory == NULL)
return NULL;
struct dirent *name = NULL;
int indexHtmlFound = 0;
int indexPhpFound = 0;
do {
name = readdir(directory);
if (name != NULL)
{
if(!(strcmp(name->d_name, "index.html")))
{
indexHtmlFound = 1;
break;
}
if(!(strcmp(name->d_name, "index.php")))
{
indexPhpFound = 1;
break;
}
}
} while(name != NULL);
closedir(directory);
char *newPath = malloc(sizeof(path)+11);
if (newPath == NULL)
return NULL;
strcpy(newPath, path);
newPath[strlen(path)] = '\0';
if(indexHtmlFound)
{
strcat(newPath, "index.html");
newPath[strlen(newPath)] = '\0';
}
else if(indexPhpFound)
{
strcat(newPath, "index.php");
newPath[strlen(newPath)] = '\0';
}
if(indexHtmlFound || indexPhpFound)
return newPath;
else
{
free(newPath);
return NULL;
}
}
valgrind server
, and ^C, it will not report any errors, because it essentially has not done anything. You need to runvalgrind server
and then send a request (browser or curl) and then ^C to get real results from valgrind. And different requests will produce different results because of the program flow.