diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 45ca470ce69bda06484feea2af2a9dec004e815f..b57cc559c331b66bfb185e5754a6b4c12753db3e 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -613,7 +613,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql, int32_t clauseIndex) { tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; } -static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg) { +static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg, int32_t *succeed) { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, 0); TSKEY dfltKey = htobe64(pQueryMsg->window.skey); @@ -626,9 +626,14 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char assert(index >= 0); SVgroupInfo* pVgroupInfo = NULL; - if (pTableMetaInfo->vgroupList->numOfVgroups > 0) { + if (pTableMetaInfo->vgroupList && pTableMetaInfo->vgroupList->numOfVgroups > 0) { assert(index < pTableMetaInfo->vgroupList->numOfVgroups); pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index]; + } else { + tscError("%p No vgroup info found", pSql); + + *succeed = 0; + return pMsg; } vgId = pVgroupInfo->vgId; @@ -948,8 +953,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->secondStageOutput = 0; } + int32_t succeed = 1; + // serialize the table info (sid, uid, tags) - pMsg = doSerializeTableInfo(pQueryMsg, pSql, pMsg); + pMsg = doSerializeTableInfo(pQueryMsg, pSql, pMsg, &succeed); + if (succeed == 0) { + return TSDB_CODE_TSC_APP_ERROR; + } SSqlGroupbyExpr *pGroupbyExpr = &pQueryInfo->groupbyExpr; if (pGroupbyExpr->numOfGroupCols > 0) { @@ -2064,19 +2074,23 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { assert(pInfo->vgroupList != NULL); pInfo->vgroupList->numOfVgroups = pVgroupMsg->numOfVgroups; - for (int32_t j = 0; j < pInfo->vgroupList->numOfVgroups; ++j) { - //just init, no need to lock - SVgroupInfo *pVgroups = &pInfo->vgroupList->vgroups[j]; + if (pInfo->vgroupList->numOfVgroups <= 0) { + tfree(pInfo->vgroupList); + } else { + for (int32_t j = 0; j < pInfo->vgroupList->numOfVgroups; ++j) { + //just init, no need to lock + SVgroupInfo *pVgroups = &pInfo->vgroupList->vgroups[j]; - SVgroupMsg *vmsg = &pVgroupMsg->vgroups[j]; - pVgroups->vgId = htonl(vmsg->vgId); - pVgroups->numOfEps = vmsg->numOfEps; + SVgroupMsg *vmsg = &pVgroupMsg->vgroups[j]; + pVgroups->vgId = htonl(vmsg->vgId); + pVgroups->numOfEps = vmsg->numOfEps; - assert(pVgroups->numOfEps >= 1 && pVgroups->vgId >= 1); + assert(pVgroups->numOfEps >= 1 && pVgroups->vgId >= 1); - for (int32_t k = 0; k < pVgroups->numOfEps; ++k) { - pVgroups->epAddr[k].port = htons(vmsg->epAddr[k].port); - pVgroups->epAddr[k].fqdn = strndup(vmsg->epAddr[k].fqdn, tListLen(vmsg->epAddr[k].fqdn)); + for (int32_t k = 0; k < pVgroups->numOfEps; ++k) { + pVgroups->epAddr[k].port = htons(vmsg->epAddr[k].port); + pVgroups->epAddr[k].fqdn = strndup(vmsg->epAddr[k].fqdn, tListLen(vmsg->epAddr[k].fqdn)); + } } }