未验证 提交 60efc075 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #18390 from taosdata/szhou/fixbugs24

fix: core dump due to assert reallocation result when reallocate fails
......@@ -227,8 +227,6 @@ tOrderDescriptor *tOrderDesCreate(const int32_t *orderColIdx, int32_t numOfOrder
void tOrderDescDestroy(tOrderDescriptor *pDesc);
void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t index, __compar_fn_t compareFn);
void tColModelAppend(SColumnModel *dstModel, tFilePage *dstPage, void *srcData, int32_t srcStartRows,
int32_t numOfRowsToWrite, int32_t srcCapacity);
......@@ -239,7 +237,7 @@ void tColDataQSort(tOrderDescriptor *, int32_t numOfRows, int32_t start, int32_t
void tColDataMergeSort(tOrderDescriptor *, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType);
void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t index, __compar_fn_t compareFn);
int32_t taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t index, __compar_fn_t compareFn);
int32_t compare_sa(tOrderDescriptor *, int32_t numOfRows, int32_t idx1, int32_t idx2, char *data);
......
......@@ -5959,7 +5959,13 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
__compar_fn_t comp = getKeyComparFunc(pSchema[pInfo->colIndex].type, pInfo->order);
if (pInfo->pDataBlock->info.rows) {
taoscQSort(pCols, pSchema, numOfCols, pInfo->pDataBlock->info.rows, pInfo->colIndex, comp);
int32_t code = taoscQSort(pCols, pSchema, numOfCols, pInfo->pDataBlock->info.rows, pInfo->colIndex, comp);
if (code != TSDB_CODE_SUCCESS) {
qError("QInfo:0x%"PRIx64 " can not sort since %s", GET_QID(pOperator->pRuntimeEnv), tstrerror(code));
tfree(pCols);
tfree(pSchema);
longjmp(pOperator->pRuntimeEnv->env, code);
}
}
tfree(pCols);
......
......@@ -1246,7 +1246,7 @@ void tOrderDescDestroy(tOrderDescriptor *pDesc) {
tfree(pDesc);
}
void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t idx, __compar_fn_t compareFn) {
int32_t taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t idx, __compar_fn_t compareFn) {
assert(numOfRows > 0 && numOfCols > 0 && idx >= 0 && idx < numOfCols);
int32_t bytes = pSchema[idx].bytes;
......@@ -1278,7 +1278,12 @@ void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOf
// make sure memory buffer is enough
if (prevLength < bytes1) {
char *tmp = realloc(p, bytes1 * numOfRows);
assert(tmp);
if (tmp == NULL) {
qError("can not allocated memory. bytes:%d", bytes*numOfRows);
tfree(p);
tfree(buf);
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
p = tmp;
prevLength = bytes1;
......@@ -1298,4 +1303,5 @@ void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOf
tfree(buf);
tfree(p);
return TSDB_CODE_SUCCESS;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册