Sign in to follow this  
programmer_tom

winsock heap problem

Recommended Posts

programmer_tom    214
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

Share this post


Link to post
Share on other sites
Antheus    2409
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.

Share this post


Link to post
Share on other sites
programmer_tom    214


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

Share this post


Link to post
Share on other sites
Evil Steve    2017
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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...

Share this post


Link to post
Share on other sites
wodinoneeye    1689
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.

Share this post


Link to post
Share on other sites
programmer_tom    214
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this