antirez / antirez/sds

memory leak in sdssplitlen() ?

Offen
#43 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C
Sterne
5.6k
Forks
510
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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`?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.