[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.
This commit is contained in:
parent
7002d9635e
commit
4f4c4368b3
|
@ -192,7 +192,12 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
|||
pVnode->status = TAOS_VN_STATUS_INIT;
|
||||
pVnode->refCount = 1;
|
||||
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);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -278,6 +283,7 @@ vnodeOpenError:
|
|||
}
|
||||
if (pVnode != NULL) {
|
||||
taosDeleteIntHash(tsDnodeVnodesHash, pVnode->vgId);
|
||||
free(pVnode);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue