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

@ -198,6 +198,11 @@ static int32_t generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int
} }
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}; MonitorSlowLogData data = {0};
data.clusterId = pTscObj->pAppInfo->clusterId; data.clusterId = pTscObj->pAppInfo->clusterId;
data.type = SLOW_LOG_WRITE; 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; char* pCont = NULL;
int64_t totalSize = 0; int64_t totalSize = 0;
if (size - *offset >= SLOW_LOG_SEND_SIZE_MAX) { 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; totalSize = 4 + SLOW_LOG_SEND_SIZE_MAX;
} else { } else {
pCont = taosMemoryCalloc(1, 4 + (size - *offset));
totalSize = 4 + (size - *offset); totalSize = 4 + (size - *offset);
} }
pCont = taosMemoryCalloc(1, totalSize); // 4 reserved for []
if (pCont == NULL) { if (pCont == NULL) {
tscError("failed to allocate memory for slow log, size:%" PRId64, totalSize); tscError("failed to allocate memory for slow log, size:%" PRId64, totalSize);
return NULL; return NULL;
} }
char* buf = pCont; char* buf = pCont;
(void)strcat(buf++, "["); (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) {
if (readSize < 0) { if (readSize < 0) {
tscError("failed to read len from file:%p since %s", pFile, terrstr()); 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; return terrno;
} }
int64_t res = 0;
DWORD bytesRead; DWORD bytesRead;
if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) { if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) {
DWORD errCode = GetLastError(); DWORD errCode = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(errCode); terrno = TAOS_SYSTEM_WINAPI_ERROR(errCode);
bytesRead = -1; res = -1;
} else {
res = bytesRead;
} }
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
(void)taosThreadRwlockUnlock(&(pFile->rwlock)); (void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif #endif
return bytesRead; return res;
} }
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {