Skip to content

Commit a4b7263

Browse files
committed
fixed:sometimes memory leak when read configure
1 parent a698e0a commit a4b7263

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,12 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_Switch(LPCXSTR lpszConfigFile,
332332
Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_OPENFILE;
333333
return false;
334334
}
335-
size_t nCount = 0;
336-
XCHAR tszMsgBuffer[4096];
337-
while (1)
338-
{
339-
size_t nRet = fread(tszMsgBuffer + nCount, 1, 2048, pSt_File);
340-
if (nRet <= 0)
341-
{
342-
break;
343-
}
344-
nCount += nRet;
345-
}
335+
XCHAR tszMsgBuffer[8192] = {};
336+
size_t nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
346337
fclose(pSt_File);
347338
//开始解析配置文件
348339
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
349-
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nCount, &st_JsonRoot, &st_JsonError))
340+
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nRet, &st_JsonRoot, &st_JsonError))
350341
{
351342
Config_IsErrorOccur = true;
352343
Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_PARSE;

0 commit comments

Comments
 (0)