summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiadlo <polsha3@gmail.com>2017-03-12 10:45:09 +0300
committeriphydf <iphydf@users.noreply.github.com>2017-03-26 12:51:30 +0000
commitc07c61c5efa63ff414ce92c6174675e05da64e25 (patch)
tree9c4d252d195271c33507fcbbd5359103dfbeb3d0
parentf675474c084e1e699c064f04d3984ff10706d915 (diff)
Fix list malloc(0) bug
-rw-r--r--toxcore/list.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/toxcore/list.c b/toxcore/list.c
index d9bfe021..36d609fb 100644
--- a/toxcore/list.c
+++ b/toxcore/list.c
@@ -117,6 +117,11 @@ static int find(const BS_LIST *list, const uint8_t *data)
117 */ 117 */
118static int resize(BS_LIST *list, uint32_t new_size) 118static int resize(BS_LIST *list, uint32_t new_size)
119{ 119{
120 if (new_size == 0) {
121 bs_list_free(list);
122 return 1;
123 }
124
120 uint8_t *data = (uint8_t *)realloc(list->data, list->element_size * new_size); 125 uint8_t *data = (uint8_t *)realloc(list->data, list->element_size * new_size);
121 126
122 if (!data) { 127 if (!data) {
@@ -161,7 +166,10 @@ void bs_list_free(BS_LIST *list)
161{ 166{
162 //free both arrays 167 //free both arrays
163 free(list->data); 168 free(list->data);
169 list->data = NULL;
170
164 free(list->ids); 171 free(list->ids);
172 list->ids = NULL;
165} 173}
166 174
167int bs_list_find(const BS_LIST *list, const uint8_t *data) 175int bs_list_find(const BS_LIST *list, const uint8_t *data)