fix: windows crash

This commit is contained in:
xsren 2024-09-25 14:08:32 +08:00
parent 7273bd9219
commit ecf5f35cd0
3 changed files with 13 additions and 6 deletions

View File

@ -197,7 +197,12 @@ static int32_t generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString("")));
}
char *value = cJSON_PrintUnformatted(json);
char *value = cJSON_PrintUnformatted(json);
if (value == NULL) {
tscError("failed to print json");
code = TSDB_CODE_FAILED;
goto _end;
}
MonitorSlowLogData data = {0};
data.clusterId = pTscObj->pAppInfo->clusterId;
data.type = SLOW_LOG_WRITE;

View File

@ -447,20 +447,19 @@ static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) {
char* pCont = NULL;
int64_t totalSize = 0;
if (size - *offset >= SLOW_LOG_SEND_SIZE_MAX) {
pCont = taosMemoryCalloc(1, 4 + SLOW_LOG_SEND_SIZE_MAX); // 4 reserved for []
totalSize = 4 + SLOW_LOG_SEND_SIZE_MAX;
} else {
pCont = taosMemoryCalloc(1, 4 + (size - *offset));
totalSize = 4 + (size - *offset);
}
pCont = taosMemoryCalloc(1, totalSize); // 4 reserved for []
if (pCont == NULL) {
tscError("failed to allocate memory for slow log, size:%" PRId64, totalSize);
return NULL;
}
char* buf = pCont;
(void)strcat(buf++, "[");
int64_t readSize = taosReadFile(pFile, buf, SLOW_LOG_SEND_SIZE_MAX);
int64_t readSize = taosReadFile(pFile, buf, totalSize - 4); // 4 reserved for []
if (readSize <= 0) {
if (readSize < 0) {
tscError("failed to read len from file:%p since %s", pFile, terrstr());

View File

@ -426,16 +426,19 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
return terrno;
}
int64_t res = 0;
DWORD bytesRead;
if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) {
DWORD errCode = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(errCode);
bytesRead = -1;
res = -1;
} else {
res = bytesRead;
}
#if FILE_WITH_LOCK
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
return bytesRead;
return res;
}
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {