winsock heap problem

Started by
6 comments, last by programmer_tom 17 years, 1 month ago
hi all. working with winsock for LAN multiplayer. everything works just fine until i shut down the sockets and re-create them. the compiler gives me a corrupted heap error. i think i've narrowed it down the the call to recvfrom() when our listen thread is starting, but don't really understand why this affects the problem. thanks -programmer_tom
Advertisement
This usually indicates buffer overrun. Somewhere in your code, you're likely writing beyond your allocated memory. In recvfrom, the buffer and buffer length parameters would be good source of this.

Other than that, it could be any dangling pointer, unallocated pointer, or other usual suspects for memory corruption.
            char        szBuffer[MAX_MSG_LEN] = "\0";      SOCKADDR_IN saInClient;      int         nAddrSize = sizeof saInClient;              int nRet = recvfrom ( m_socket,                 // Bound socket                            szBuffer,                 // Receive buffer                            MAX_MSG_LEN,              // Size of buffer in bytes                            0,                        // Flags                            (sockaddr*) &saInClient,  // Buffer to receive client address                              &nAddrSize );             // Length of client address buffer
You know you can edit your posts?

There's no reference anywhere there to the heap - no STL containers, and nothing using malloc / new, so that isn't where your problem is.
What Steve said, edit and delete your first two posts with the code in it.

Also what Steve said, that is not where your problem is, besides some interesting programming habits...
nm, misread the original code.

[Edited by - Antheus on March 6, 2007 12:52:33 PM]
Its hard to say without seeing more of your code (esp the part 'shut down the sockets and re-create them').

I would test every return code from every one of the socket lib functions to make sure they are doing the right things the second time thru.
--------------------------------------------[size="1"]Ratings are Opinion, not Fact
thx guys. i didn't know you could edit your posts. i also realize nothing is being put on the heap there, which makes it tougher to debug. i went through once and tested the return codes from all the winsock calls and they all come back ok. i'll go through it again.

the reason i'm creating and destroying the objects is i wanted to create a network browsing screen for our game that shows other games on the lan. when you select join or host, the client/server setup may change so i thought why not just close it down, and reopen it under different slient/server setup (rather than changing around the properties of the in/out sockets).

nothing i've see in the documentation says you cannot do this.
is it illegal to call WSAStartup and WSACleanup more than once during execution?

This topic is closed to new replies.

Advertisement