From 1f72417ee65a6072e44318bf545a3a4ed21ac7f8 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 8 Jul 2020 21:33:10 +0800 Subject: [PATCH] fix invalid read --- src/util/src/tskiplist.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index f3c0babe6b..045de3aa2f 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -498,7 +498,17 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode) { if (pSkipList->lock) { pthread_rwlock_wrlock(pSkipList->lock); } - + + if (pSkipList->size == 1) { + assert(pSkipList->lastKey == SL_GET_NODE_KEY(pSkipList, pNode)); + pSkipList->lastKey = 0; + } else { + if (pSkipList->lastKey == SL_GET_NODE_KEY(pSkipList, pNode)) { + SSkipListNode* prev = SL_GET_BACKWARD_POINTER(pNode, 0); + pSkipList->lastKey = SL_GET_NODE_KEY(pSkipList, prev); + } + } + for (int32_t j = level - 1; j >= 0; --j) { SSkipListNode* prev = SL_GET_BACKWARD_POINTER(pNode, j); SSkipListNode* next = SL_GET_FORWARD_POINTER(pNode, j); -- GitLab