Freeing a character pointer returns error

Posted by Kraffs on Stack Overflow See other posts from Stack Overflow or by Kraffs
Published on 2012-11-17T22:54:11Z Indexed on 2012/11/17 23:00 UTC
Read the original article Hit count: 186

Filed under:
|
|
|

I'm trying to free a character pointer after having used it but it returns a strange error.

The error says: "_CrtDbgREport: String too long or IO Error"

The debugger itself returns no errors while compiling.

The code currently looks like this:

void RespondToUser(SOCKET client, SOCKET server)
{
    char buffer[80];
    char *temp = malloc(_scprintf("HTTP/1.1 200 OK\r\n%s\r\nServer: %s\r\nConnection: close\r\n\r\nHi!", buffer, SERVER_NAME));
    sprintf(temp, "HTTP/1.1 200 OK\r\n%s\r\nServer: %s\r\nConnection: close\r\n\r\nHi!", buffer, SERVER_NAME);

    send(client, temp, strlen(temp), 0);
    closesocket(client);
    free(temp);
    ListenToUsers(server);
}

The problem only occurs when I try to free the temp pointer from the memory and not otherwise. What might be causing this?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointers