summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMasaki Muranaka <[email protected]>2013-04-01 08:40:05 +0900
committerMasaki Muranaka <[email protected]>2013-04-01 08:40:05 +0900
commitc7ff1bd88150c8f61f7483ea857f198ca1992fc7 (patch)
tree583d28aa0f9b83739ab8fdfa93170a77209e7573 /src
parent29879f9d582416f205555260fbe9ac8a3d9013ba (diff)
downloadmruby-c7ff1bd88150c8f61f7483ea857f198ca1992fc7.tar.gz
mruby-c7ff1bd88150c8f61f7483ea857f198ca1992fc7.zip
Add the care for malloc failed.
At the first time, mrb_realloc raise RuntimeError. At the time fails twice in a row, it causes panic.
Diffstat (limited to 'src')
-rw-r--r--src/gc.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gc.c b/src/gc.c
index c90e00c89..07bc23b12 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -157,6 +157,20 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len)
mrb_garbage_collect(mrb);
p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
}
+
+ if (!p2 && len) {
+ if (mrb->out_of_memory) {
+ /* mrb_panic(mrb); */
+ }
+ else {
+ mrb->out_of_memory = 1;
+ mrb_raise(mrb, E_RUNTIME_ERROR, "Out of memory");
+ }
+ }
+ else {
+ mrb->out_of_memory = 0;
+ }
+
return p2;
}