Unverified Commit 23b50bcc authored by Wen Hui's avatar Wen Hui Committed by GitHub
Browse files

refactor rewriteStreamObject code for adding missing streamIteratorStop call (#7829)

This commit adds streamIteratorStop call in rewriteStreamObject function in some of the return statement. Although currently this will not cause memory leak since stream id is only 16 bytes long.
parent 9216b96b
...@@ -1201,16 +1201,24 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) { ...@@ -1201,16 +1201,24 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
* the ID, the second is an array of field-value pairs. */ * the ID, the second is an array of field-value pairs. */
/* Emit the XADD <key> <id> ...fields... command. */ /* Emit the XADD <key> <id> ...fields... command. */
if (rioWriteBulkCount(r,'*',3+numfields*2) == 0) return 0; if (!rioWriteBulkCount(r,'*',3+numfields*2) ||
if (rioWriteBulkString(r,"XADD",4) == 0) return 0; !rioWriteBulkString(r,"XADD",4) ||
if (rioWriteBulkObject(r,key) == 0) return 0; !rioWriteBulkObject(r,key) ||
if (rioWriteBulkStreamID(r,&id) == 0) return 0; !rioWriteBulkStreamID(r,&id))
{
streamIteratorStop(&si);
return 0;
}
while(numfields--) { while(numfields--) {
unsigned char *field, *value; unsigned char *field, *value;
int64_t field_len, value_len; int64_t field_len, value_len;
streamIteratorGetField(&si,&field,&value,&field_len,&value_len); streamIteratorGetField(&si,&field,&value,&field_len,&value_len);
if (rioWriteBulkString(r,(char*)field,field_len) == 0) return 0; if (!rioWriteBulkString(r,(char*)field,field_len) ||
if (rioWriteBulkString(r,(char*)value,value_len) == 0) return 0; !rioWriteBulkString(r,(char*)value,value_len))
{
streamIteratorStop(&si);
return 0;
}
} }
} }
} else { } else {
...@@ -1218,22 +1226,30 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) { ...@@ -1218,22 +1226,30 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
* the key we are serializing is an empty string, which is possible * the key we are serializing is an empty string, which is possible
* for the Stream type. */ * for the Stream type. */
id.ms = 0; id.seq = 1; id.ms = 0; id.seq = 1;
if (rioWriteBulkCount(r,'*',7) == 0) return 0; if (!rioWriteBulkCount(r,'*',7) ||
if (rioWriteBulkString(r,"XADD",4) == 0) return 0; !rioWriteBulkString(r,"XADD",4) ||
if (rioWriteBulkObject(r,key) == 0) return 0; !rioWriteBulkObject(r,key) ||
if (rioWriteBulkString(r,"MAXLEN",6) == 0) return 0; !rioWriteBulkString(r,"MAXLEN",6) ||
if (rioWriteBulkString(r,"0",1) == 0) return 0; !rioWriteBulkString(r,"0",1) ||
if (rioWriteBulkStreamID(r,&id) == 0) return 0; !rioWriteBulkStreamID(r,&id) ||
if (rioWriteBulkString(r,"x",1) == 0) return 0; !rioWriteBulkString(r,"x",1) ||
if (rioWriteBulkString(r,"y",1) == 0) return 0; !rioWriteBulkString(r,"y",1))
{
streamIteratorStop(&si);
return 0;
}
} }
/* Append XSETID after XADD, make sure lastid is correct, /* Append XSETID after XADD, make sure lastid is correct,
* in case of XDEL lastid. */ * in case of XDEL lastid. */
if (rioWriteBulkCount(r,'*',3) == 0) return 0; if (!rioWriteBulkCount(r,'*',3) ||
if (rioWriteBulkString(r,"XSETID",6) == 0) return 0; !rioWriteBulkString(r,"XSETID",6) ||
if (rioWriteBulkObject(r,key) == 0) return 0; !rioWriteBulkObject(r,key) ||
if (rioWriteBulkStreamID(r,&s->last_id) == 0) return 0; !rioWriteBulkStreamID(r,&s->last_id))
{
streamIteratorStop(&si);
return 0;
}
/* Create all the stream consumer groups. */ /* Create all the stream consumer groups. */
...@@ -1252,6 +1268,7 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) { ...@@ -1252,6 +1268,7 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
!rioWriteBulkStreamID(r,&group->last_id)) !rioWriteBulkStreamID(r,&group->last_id))
{ {
raxStop(&ri); raxStop(&ri);
streamIteratorStop(&si);
return 0; return 0;
} }
...@@ -1277,6 +1294,7 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) { ...@@ -1277,6 +1294,7 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
raxStop(&ri_pel); raxStop(&ri_pel);
raxStop(&ri_cons); raxStop(&ri_cons);
raxStop(&ri); raxStop(&ri);
streamIteratorStop(&si);
return 0; return 0;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment