Valgrind を実行して、コードのメモリ リークをチェックしています。Valgrind はリークが発生していることを示していませんが、リークを引き起こしていると思われるコードがあり、変数がどのようにクリーンアップされているのか、または Valgrind がそれをキャッチしていないのかわかりません。2 つの char* 配列でリークが発生しないのはなぜですか?
void BasicEngine::ConnectionInput(int ConnectionId, const char* ClientInput)
{
// find client assignment to this ConnectionId
Client* thisClient = this->ClientFind(ConnectionId);
int SpaceLocation = strcspn(ClientInput," ");
char* verb;
char* args;
if(SpaceLocation == strlen(ClientInput))
{
verb = (char*)ClientInput;
args = (char*)"";
}
else
{
verb = new char[SpaceLocation+1];
args = new char[strlen(ClientInput)-SpaceLocation+1];
sscanf(ClientInput,"%s %[^\n]",verb,args);
}
if(thisClient != NULL)
{
// ... client is always null, this is not being reached at the moment.
}
else
{
if(this->refCmdHandler != NULL)
if(this->refCmdHandler->cmdHandler(ConnectionId,ClientInput))
return;
}
this->refServer->TransmitNL(ConnectionId,"Invalid Command.");
}
bool BasicCmdProc::cmdHandler(int ConnectionId, string ClientInput)
{
Transmit(ConnectionId,string("You Said: ") + ClientInput);
return true;
}
「こんにちは」と入力すると
出力は次のとおりです。
漏れは検出されません。