提交 4f4c4368 编写于 作者: Y yifan hao

[vnode] Handle failure of adding to hash in vnodeOpen().

This patch adds error handling for call to vnodeOpen() in vnodeOpen.
Previously the error is not handled, which could cause the allocated
pVnode not registered anywhere, and this could cause memory leak.

This patch also adds a missing deallocation of pVnode on failure.
taosDeleteIntHash() only removes the pVnode from hash table, but
pVnode needs to be deallocated explicitly.
上级 7002d963
...@@ -192,7 +192,12 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { ...@@ -192,7 +192,12 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
pVnode->status = TAOS_VN_STATUS_INIT; pVnode->status = TAOS_VN_STATUS_INIT;
pVnode->refCount = 1; pVnode->refCount = 1;
pVnode->version = 0; pVnode->version = 0;
taosAddIntHash(tsDnodeVnodesHash, pVnode->vgId, (char *)(&pVnode)); void *pData = taosAddIntHash(tsDnodeVnodesHash, pVnode->vgId, (char *)(&pVnode));
if (pData == NULL) {
dError("pVnode:%p vgId:%d, failed to add to hash", pVnode, pVnode->vgId);
code = TSDB_CODE_VG_INIT_FAILED;
goto vnodeOpenError;
}
code = vnodeReadCfg(pVnode); code = vnodeReadCfg(pVnode);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -278,6 +283,7 @@ vnodeOpenError: ...@@ -278,6 +283,7 @@ vnodeOpenError:
} }
if (pVnode != NULL) { if (pVnode != NULL) {
taosDeleteIntHash(tsDnodeVnodesHash, pVnode->vgId); taosDeleteIntHash(tsDnodeVnodesHash, pVnode->vgId);
free(pVnode);
} }
return code; return code;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册