So, I continue to work with this error: free(): invalid next size(fast)when I run my code. If I delete the free one at the end of the function, I know that I have a memory leak, but I do not understand why I am getting this error.
I assume this is due to the fact that I am allocating memory incorrectly, but I cannot find a fix, here is my code:
bool parse(const char* line)
{
char* copy = malloc(sizeof(line));
strcpy(copy, line);
char* method = strtok(copy, " ");
char* reqLine = strtok(NULL, " ");
char* version = strtok(NULL, "\r\n");
if (strcmp(method,"GET") != 0)
{
printf("%s\n", method);
printf("ERROR 405\n");
return false;
}
if (strncmp(reqLine, "/", 1) != 0)
{
printf("%c\n", reqLine[0]);
printf("%s\n", reqLine);
printf("ERROR 501\n");
return false;
}
if (strchr(reqLine, 34) != NULL)
{
printf("%s\n", reqLine);
printf("ERROR 400\n");
return false;
}
if (strcmp(version, "HTTP/1.1") != 0)
{
printf("%s", version);
printf("ERROR 505\n");
return false;
}
return true;
}
If this helps the const char*form passed in a line :
method SP request-target SP HTTP-version CRLF
Where SP is the space, and CRLF is the carriage return, line feed.
source
share