Check the result of malloc in string_list_add (#1495)

This commit is contained in:
Michael Jones 2024-05-29 22:49:54 -05:00 committed by GitHub
parent 35a3293531
commit e45d846331
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -838,9 +838,16 @@ static string_list *string_list_add(string_list *sl, const ur_string_map_key_typ
return sl;
}
string_elem *elem = (string_elem *)malloc(sizeof(string_elem));
if (!elem) {
return sl;
}
elem->list.next = sl;
elem->key_size = strlen(key) + 1;
elem->key = (char *)malloc(elem->key_size);
if (!elem->key) {
free(elem);
return sl;
}
memcpy(elem->key, key, elem->key_size);
elem->value = value;
return &(elem->list);