properly handle if the realloc() is failed.
@Isssue: https://github.com/Samsung/thorvg/issues/995
{
if (count + 1 > reserved) {
reserved = (count + 1) * 2;
+ auto p = data;
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
+ if (!data) {
+ data = p;
+ return;
+ }
}
data[count++] = element;
}
{
if (size > reserved) {
reserved = size;
+ auto p = data;
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
- if (!data) return false;
+ if (!data) {
+ data = p;
+ return false;
+ }
}
return true;
}