Skip to content

Commit

Permalink
Merge pull request #23830 from taosdata/fix/liaohj
Browse files Browse the repository at this point in the history
fix(stream): fix invalid free.
  • Loading branch information
hjxilinx committed Nov 28, 2023
2 parents d51baab + b419650 commit 8b406c0
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions source/dnode/mnode/impl/src/mndStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,14 @@ static int32_t checkForNumOfStreams(SMnode *pMnode, SStreamObj *pStreamObj) { /
}

static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
SMnode * pMnode = pReq->info.node;
int32_t code = -1;
SStreamObj * pStream = NULL;
SDbObj * pDb = NULL;
SCMCreateStreamReq createStreamReq = {0};
SStreamObj streamObj = {0};
SMnode *pMnode = pReq->info.node;
int32_t code = -1;
SStreamObj *pStream = NULL;
SStreamObj streamObj = {0};
char *sql = NULL;
int32_t sqlLen = 0;

SCMCreateStreamReq createStreamReq = {0};
if (tDeserializeSCMCreateStreamReq(pReq->pCont, pReq->contLen, &createStreamReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
Expand Down Expand Up @@ -790,9 +791,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
goto _OVER;
}

char* sql = NULL;
int32_t sqlLen = 0;
if(createStreamReq.sql != NULL){
if (createStreamReq.sql != NULL) {
sqlLen = strlen(createStreamReq.sql);
sql = taosMemoryMalloc(sqlLen + 1);
memset(sql, 0, sqlLen + 1);
Expand Down Expand Up @@ -879,14 +878,13 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
// reuse this function for stream

if (sql != NULL && sqlLen > 0) {
auditRecord(pReq, pMnode->clusterId, "createStream", dbname.dbname, name.dbname, sql,
sqlLen);
}
else{
auditRecord(pReq, pMnode->clusterId, "createStream", dbname.dbname, name.dbname, sql, sqlLen);
} else {
char detail[1000] = {0};
sprintf(detail, "dbname:%s, stream name:%s", dbname.dbname, name.dbname);
auditRecord(pReq, pMnode->clusterId, "createStream", dbname.dbname, name.dbname, detail, strlen(detail));
}

_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr());
Expand All @@ -895,7 +893,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
mndReleaseStream(pMnode, pStream);
tFreeSCMCreateStreamReq(&createStreamReq);
tFreeStreamObj(&streamObj);
if(sql != NULL){
if (sql != NULL) {
taosMemoryFreeClear(sql);
}
return code;
Expand Down

0 comments on commit 8b406c0

Please sign in to comment.