From 35c70a73a0336c56d08c9f815134d39b316c015b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 17 Jun 2020 08:03:22 +0000 Subject: [PATCH] invalid write while alter vgroup --- src/mnode/src/mnodeSdb.c | 4 ++-- src/mnode/src/mnodeVgroup.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index c0c5b9df30..d8fc9aee5a 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -389,7 +389,7 @@ void sdbIncRef(void *handle, void *pObj) { SSdbTable *pTable = handle; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); atomic_add_fetch_32(pRefCount, 1); - if (1) { + if (0 && (pTable->tableId == SDB_TABLE_CTABLE || pTable->tableId == SDB_TABLE_DB)) { sdbTrace("add ref to table:%s record:%p:%s:%d", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), *pRefCount); } } @@ -400,7 +400,7 @@ void sdbDecRef(void *handle, void *pObj) { SSdbTable *pTable = handle; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); - if (1) { + if (0 && (pTable->tableId == SDB_TABLE_CTABLE || pTable->tableId == SDB_TABLE_DB)) { sdbTrace("def ref of table:%s record:%p:%s:%d", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), *pRefCount); } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 0475a48ce2..efa823d531 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -149,9 +149,17 @@ static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) { } } + void *idPool = pVgroup->idPool; + void *tableList = pVgroup->tableList; + int32_t oldRefCount = pVgroup->refCount; + memcpy(pVgroup, pNew, sizeof(SVgObj)); + free(pNew); - + pVgroup->refCount = oldRefCount; + pVgroup->idPool = idPool; + pVgroup->tableList = tableList; + for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { SDnodeObj *pDnode = mnodeGetDnode(pVgroup->vnodeGid[i].dnodeId); pVgroup->vnodeGid[i].pDnode = pDnode; -- GitLab