summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMasaki Muranaka <[email protected]>2013-03-28 17:57:52 +0900
committerMasaki Muranaka <[email protected]>2013-03-28 17:57:52 +0900
commit31bb00b9c2d84e1e2c7efe64675f78ac99c3a399 (patch)
tree44a8899c8b26b08830aa8695c47f041b6901e426 /src
parente265d7c7efe51bc425e39c7fa208a6f421bba199 (diff)
downloadmruby-31bb00b9c2d84e1e2c7efe64675f78ac99c3a399.tar.gz
mruby-31bb00b9c2d84e1e2c7efe64675f78ac99c3a399.zip
Add arena guard. It will be exausted when the pool is huge.
Diffstat (limited to 'src')
-rw-r--r--src/dump.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/dump.c b/src/dump.c
index d3f6ee62b..f4c48d951 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -76,6 +76,8 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep)
size += irep->plen * (sizeof(uint8_t) + sizeof(uint16_t)); /* len(n) */
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
+ int ai = mrb_gc_arena_save(mrb);
+
switch (mrb_type(irep->pool[pool_no])) {
case MRB_TT_FIXNUM:
str = mrb_fix2str(mrb, irep->pool[pool_no], 10);
@@ -95,6 +97,8 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep)
default:
break;
}
+
+ mrb_gc_arena_restore(mrb, ai);
}
return size;
@@ -120,6 +124,8 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
cur += uint32_to_bin(irep->plen, cur); /* number of pool */
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
+ int ai = mrb_gc_arena_save(mrb);
+
cur += uint8_to_bin(mrb_type(irep->pool[pool_no]), cur); /* data type */
memset(char_buf, 0, buf_size);
@@ -141,6 +147,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
buf_size = len + 1;
char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size);
if (char_buf == NULL) {
+ mrb_gc_arena_restore(mrb, ai);
result = MRB_DUMP_GENERAL_FAILURE;
goto error_exit;
}
@@ -157,6 +164,8 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
cur += uint16_to_bin(len, cur); /* data length */
memcpy(cur, char_buf, len);
cur += len;
+
+ mrb_gc_arena_restore(mrb, ai);
}
result = (int)(cur - buf);