diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-08-12 12:12:03 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-08-12 12:12:03 -0400 |
commit | 3306dfd21348c7a724b0a7ae0f167ec4c69b7c40 (patch) | |
tree | 5a55e328cb6e8005c7e379939c4bf7c6a3170b86 | |
parent | 809773474d2590fbace4eed3f6377c75d3d11589 (diff) | |
download | stasis-3306dfd21348c7a724b0a7ae0f167ec4c69b7c40.tar.gz |
bugfix: free data at index during strlist_set operation
* Previous behavior of setting the pointer to NULL introduced a subtle memory leak
* Set strlist error when index it out of range
-rw-r--r-- | src/strlist.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/strlist.c b/src/strlist.c index d1bb926..de76744 100644 --- a/src/strlist.c +++ b/src/strlist.c @@ -315,11 +315,12 @@ size_t strlist_count(struct StrList *pStrList) { void strlist_set(struct StrList **pStrList, size_t index, char *value) { char *tmp = NULL; if (*pStrList == NULL || index > strlist_count(*pStrList)) { + strlist_errno = STRLIST_E_OUT_OF_RANGE; return; } if (value == NULL) { - (*pStrList)->data[index] = NULL; + guard_free((*pStrList)->data[index]); } else { tmp = realloc((*pStrList)->data[index], (strlen(value) + 1) * sizeof(char *)); if (!tmp) { |