summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorCarson McDonald <[email protected]>2013-03-05 15:22:10 -0500
committerCarson McDonald <[email protected]>2013-03-05 15:22:10 -0500
commitf792552a5e907da3354673e16de9fc7c6b448c36 (patch)
tree82c8d847e1a716f8778637e30a988a955c11fdcc /src
parent6d0e2519dd3e432339b1cb75a0379df6cb8ff518 (diff)
downloadmruby-f792552a5e907da3354673e16de9fc7c6b448c36.tar.gz
mruby-f792552a5e907da3354673e16de9fc7c6b448c36.zip
Add null check after mrb_realloc for array
Diffstat (limited to 'src')
-rw-r--r--src/array.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/array.c b/src/array.c
index b55a47f66..b8cd436f0 100644
--- a/src/array.c
+++ b/src/array.c
@@ -192,8 +192,14 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len)
if (capa > ARY_MAX_SIZE) capa = ARY_MAX_SIZE; /* len <= capa <= ARY_MAX_SIZE */
if (capa > a->aux.capa) {
+ mrb_value *expanded_ptr = (mrb_value *)mrb_realloc(mrb, a->ptr, sizeof(mrb_value)*capa);
+
+ if(!expanded_ptr) {
+ mrb_raise(mrb, E_RUNTIME_ERROR, "out of memory");
+ }
+
a->aux.capa = capa;
- a->ptr = (mrb_value *)mrb_realloc(mrb, a->ptr, sizeof(mrb_value)*capa);
+ a->ptr = expanded_ptr;
}
}