diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-10-31 12:05:07 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-10-31 12:05:07 -0400 |
commit | a3f18180ea3a5aa15f75623637152800424ce8fd (patch) | |
tree | 90abf9aaf2dd2d751a3f66c633ee4013fd48a5d6 | |
parent | 8a2e123abe5bbfc8787035e5b8f77fbccdec113b (diff) | |
download | stasis-a3f18180ea3a5aa15f75623637152800424ce8fd.tar.gz |
Fixes potential double-free condition
* Only free pStrList->data[i] and pStrList->data if they are not NULL
* Free tokenized string after append
-rw-r--r-- | src/strlist.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/strlist.c b/src/strlist.c index 9cb09d0..d228405 100644 --- a/src/strlist.c +++ b/src/strlist.c @@ -15,9 +15,13 @@ void strlist_free(struct StrList *pStrList) { return; } for (size_t i = 0; i < pStrList->num_inuse; i++) { - free(pStrList->data[i]); + if (pStrList->data[i]) { + free(pStrList->data[i]); + } + } + if (pStrList->data) { + free(pStrList->data); } - free(pStrList->data); free(pStrList); } @@ -164,6 +168,7 @@ void strlist_append_strlist(struct StrList *pStrList1, struct StrList *pStrList2 for (size_t i = 0; token[i] != NULL; i++) { strlist_append(pStrList, token[i]); } + split_free(token); } } |