This is my code to extract the filename requested from the server from the request message:
char* buffer2 = strchr(buffer1, '/');
char* buffer3 = strchr(buffer2, ' ');
char* buffer4 = malloc(strlen(buffer2) - strlen(buffer3));
if (!buffer4)
{
error(500);
return false;
}
strncpy(buffer4, buffer2, (strlen(buffer2) - strlen(buffer3)));
Later on, buffer4 is copied to abs_path.
This code works perfectly the first or second time the image is requested, but after that buffer4 becomes things like " /cat.jpgjpg�]r" instead of just "/cat.jpg".
I always free buffer4 later after copying it to abs_path. Any suggestions on why this is happening? many thanks in advance