From c9324f81a209c49c795d41ab2af8cb06b72d87c9 Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Mon, 16 Jul 2018 15:57:41 +0800 Subject: [PATCH] Streams: free lp if all elements are deleted --- src/t_stream.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/t_stream.c b/src/t_stream.c index 54d6b0d1f..ea2cf5602 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -705,10 +705,15 @@ void streamIteratorRemoveEntry(streamIterator *si, streamID *current) { /* Change the valid/deleted entries count in the master entry. */ unsigned char *p = lpFirst(lp); aux = lpGetInteger(p); - lp = lpReplaceInteger(lp,&p,aux-1); - p = lpNext(lp,p); /* Seek deleted field. */ - aux = lpGetInteger(p); - lp = lpReplaceInteger(lp,&p,aux+1); + if (aux == 1) { + lpFree(lp); + raxRemove(si->stream->rax,si->ri.key,si->ri.key_len,NULL); + } else { + lp = lpReplaceInteger(lp,&p,aux-1); + p = lpNext(lp,p); /* Seek deleted field. */ + aux = lpGetInteger(p); + lp = lpReplaceInteger(lp,&p,aux+1); + } /* Update the number of entries counter. */ si->stream->length--;