Handle allocation failure in hb-language code

This commit is contained in:
Behdad Esfahbod 2017-06-01 11:44:42 -04:00
parent 92e2c4baaf
commit 7dba30639a
1 changed files with 11 additions and 3 deletions

View File

@ -227,9 +227,12 @@ struct hb_language_item_t {
*/
size_t len = strlen(s) + 1;
lang = (hb_language_t) malloc(len);
if (likely (lang))
{
memcpy((unsigned char *) lang, s, len);
for (unsigned char *p = (unsigned char *) lang; *p; p++)
*p = canon_map[*p];
}
return *this;
}
@ -271,6 +274,11 @@ retry:
return NULL;
lang->next = first_lang;
*lang = key;
if (unlikely (!lang->lang))
{
free (lang);
return NULL;
}
if (!hb_atomic_ptr_cmpexch (&langs, first_lang, lang)) {
lang->finish ();