Quote:str=new char[100]; str="!QUERY!LUVERSION~$"; |
You've overwritten the contents of the pointer with the address of a static string. The address returned by
new char[100] is lost (memory leak), and
delete[]-ing a static string has undefined behaviour.
Also note that since you're using the
array-
new you must use
array-
delete.
Here's the corrected code:
str=new char[100];strcpy(str, "!QUERY!LUVERSION~$");debugResult=send(clientSock,str,StringLength(str,'$'),0);delete[] str;
or, dispensing with the dynamic buffer altogether:
const char* str = "!QUERY!LUVERSION~$";debugResult=send(clientSock,str,StringLength(str,'$'),0);
Though of course, it is
much simpler to use a C++ string:
std::string str;str = "!QUERY!LUVERSION~$";debugResult=send(clientSock,str.c_str(),str.length()-1,0); // -1 for the $// no cleanup needed
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan