You return type
, which points to an array which had been allocated on the stack and is invalid after the function chktype()
has returned.
You might like to allocate the result on the heap, like this:
char * chktype(const char * buffer, int size)
{
char * strng = "Content-Type: ";
char * found = strstr (buffer, strng);
char * found1 = strstr(found, "\r\n");
size_t sz = strlen(found) - strlen(found1);
char * type = calloc(sz, sizeof(*type));
if (type)
{
strncpy(type, found1, sz - 1);
}
return type;
}
However, there is the need to free()
the result after not needed anymore.