Jump to content
  • Advertisement
Sign in to follow this  
themadme

delete problem after calling recvfrom()

This topic is 3655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this whats happening : char *pcName = new char[ strQueryName.length() ]; -> length is four recvfrom( socketUser, pcName, sizeof(pcName), 0, (SOCKADDR*)&sockClientAddress, &AddressSize ); delete [] pcName; it gives me the HEAP CORRUPTION DETECTED: CRT detected that the application wrote to memory after end of heap buffer. why is this? it has to do with the recvfrom() function because i can easily delete it before the call, with out any errors

Share this post


Link to post
Share on other sites
Advertisement
Your use of sizeof() is incorrect. The result of sizeof() on a pointer is a fixed value. You want to use the size of the buffer - which you would have to track seperately. In C++, we can use std::vector as a temporary buffer. std::vector is guaranteed to be contigious, we can obtain a pointer to the first element by using &vec.front(), and the size by use vec.size().

#include <vector>

//...

std::vector<char> buffer(queryName.length());

recvfrom( socketUser, &buffer.front(), buffer.size(), 0, (SOCKADDR*)&sockClientAddress, &AddressSize );


Finally, note the lack of "delete []" calls. std::vector<> does that for us.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!