sds.c: avoid leaking tokens when seplen < 1 || len < 0

This commit is contained in:
Charlie Somerville 2014-01-15 11:38:02 +11:00
parent cc3ee45325
commit 81c95a5fd3
1 changed files with 5 additions and 1 deletions

6
sds.c
View File

@ -295,7 +295,11 @@ sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count) {
#ifdef SDS_ABORT_ON_OOM
if (tokens == NULL) sdsOomAbort();
#endif
if (seplen < 1 || len < 0 || tokens == NULL) return NULL;
if (tokens == NULL) return NULL;
if (seplen < 1 || len < 0) {
free(tokens);
return NULL;
}
if (len == 0) {
*count = 0;
return tokens;