From 2aa551e2222a0a3dbcf5d32c38cd9036c011550c Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 5 Nov 2021 20:53:39 +0900 Subject: [PATCH] common array: + exception handling. properly handle if the realloc() is failed. @Isssue: https://github.com/Samsung/thorvg/issues/995 --- src/lib/tvgArray.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/tvgArray.h b/src/lib/tvgArray.h index 7283a833..d04e68e7 100644 --- a/src/lib/tvgArray.h +++ b/src/lib/tvgArray.h @@ -38,7 +38,12 @@ struct Array { if (count + 1 > reserved) { reserved = (count + 1) * 2; + auto p = data; data = static_cast(realloc(data, sizeof(T) * reserved)); + if (!data) { + data = p; + return; + } } data[count++] = element; } @@ -47,8 +52,12 @@ struct Array { if (size > reserved) { reserved = size; + auto p = data; data = static_cast(realloc(data, sizeof(T) * reserved)); - if (!data) return false; + if (!data) { + data = p; + return false; + } } return true; }