antirez / antirez/sds

memory leak in sdssplitlen() ?

Open
#43 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
5.6k
Forks
510
PR merge metrics
No merged PRs in 30d

Description

In `sdssplitlen()`, `slots` starts with a default of 5. Then
`tokens = malloc(sizeof(sds)*slots);`
or generally 40 bytes.

However, `if (len == 0) { *count = 0; return tokens;}`

How do we free the 40 bytes? `sdsfreesplitres()` will use a count of 0.

Am I wrong that this is technically a memory leak? Of course, this is a situation that will probably never come up, since who splits a string with 0 chars, but still, it looks incorrect.

Why do we allocate memory to `tokens` before the test for `len == 0`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.