summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2012-03-14 21:55:08 +0100
committerIvan Maidanski <ivmai@mail.ru>2012-03-15 16:46:18 +0100
commit32973f3dd9c4102762777111da5e5beaa7d302ad (patch)
treec484df7100e322ff15a3cfd31c2dc303a3eedf71 /malloc.c
parent65c0ef9421c5590be48b48f1f9c18e86c99ad1fa (diff)
Fix allocation size overflows due to rounding.
* malloc.c (GC_generic_malloc): Check if the allocation size is rounded to a smaller value. * mallocx.c (GC_generic_malloc_ignore_off_page): Likewise.
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c
index 5c3374d..6ef1094 100644
--- a/malloc.c
+++ b/malloc.c
@@ -167,6 +167,8 @@ GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k)
GC_bool init;
lg = ROUNDED_UP_GRANULES(lb);
lb_rounded = GRANULES_TO_BYTES(lg);
+ if (lb_rounded < lb)
+ return((*GC_get_oom_fn())(lb));
n_blocks = OBJ_SZ_TO_BLOCKS(lb_rounded);
init = GC_obj_kinds[k].ok_init;
LOCK();