Skip to content

[BUG] memory leak in streamGetEdgeID #10752

@Yuuoniy

Description

@Yuuoniy

Describe the bug

Hi, I found a possible memory leak in streamGetEdgeID with static analysis.

si is initialized by streamIteratorStart(), the code doesn't streamIteratorStop() on it when things done. it's a memory leak.

redis/src/t_stream.c

Lines 393 to 405 in 60250f5

void streamGetEdgeID(stream *s, int first, int skip_tombstones, streamID *edge_id)
{
streamIterator si;
int64_t numfields;
streamIteratorStart(&si,s,NULL,NULL,!first);
si.skip_tombstones = skip_tombstones;
int found = streamIteratorGetID(&si,edge_id,&numfields);
if (!found) {
streamID min_id = {0, 0}, max_id = {UINT64_MAX, UINT64_MAX};
*edge_id = first ? max_id : min_id;
}
}

According to the doc of streamIteratorStart(), we need to call streamIteratorStop() when things done.

redis/src/t_stream.c

Lines 1037 to 1058 in 60250f5

/* Initialize the stream iterator, so that we can call iterating functions
* to get the next items. This requires a corresponding streamIteratorStop()
* at the end. The 'rev' parameter controls the direction. If it's zero the
* iteration is from the start to the end element (inclusive), otherwise
* if rev is non-zero, the iteration is reversed.
*
* Once the iterator is initialized, we iterate like this:
*
* streamIterator myiterator;
* streamIteratorStart(&myiterator,...);
* int64_t numfields;
* while(streamIteratorGetID(&myiterator,&ID,&numfields)) {
* while(numfields--) {
* unsigned char *key, *value;
* size_t key_len, value_len;
* streamIteratorGetField(&myiterator,&key,&value,&key_len,&value_len);
*
* ... do what you want with key and value ...
* }
* }
* streamIteratorStop(&myiterator); */
void streamIteratorStart(streamIterator *si, stream *s, streamID *start, streamID *end, int rev) {

Thanks for your further confirmation.

To reproduce

Steps to reproduce the behavior and/or a minimal code sample.

Expected behavior

A description of what you expected to happen.

Additional information

Any additional information that is relevant to the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions