In lazy-loading, remember allocation failure

This commit is contained in:
Behdad Esfahbod 2017-01-09 22:20:38 -08:00
parent 29fb0cb727
commit ac274331c2
1 changed files with 5 additions and 3 deletions

View File

@ -447,11 +447,13 @@ struct hb_lazy_loader_t
{ {
p = (T *) calloc (1, sizeof (T)); p = (T *) calloc (1, sizeof (T));
if (unlikely (!p)) if (unlikely (!p))
return &OT::Null(T); p = const_cast<T *> (&OT::Null(T));
p->init (face); else
p->init (face);
if (unlikely (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), NULL, p))) if (unlikely (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), NULL, p)))
{ {
p->fini (); if (p != &OT::Null(T))
p->fini ();
goto retry; goto retry;
} }
} }