diff options
author | Koichi Sasada <ko1@atdot.net> | 2019-05-28 11:42:31 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2019-05-28 11:44:08 +0900 |
commit | f3bddc103d6a9d6e679ab35d1d3e8ab7aa2f3ae4 (patch) | |
tree | 6b2a524a29b05f752b8d34624f13555ba4a462a5 | |
parent | f9401d5d44dd4ae69b6a14fcccd41c2810033986 (diff) | |
download | ruby-f3bddc103d6a9d6e679ab35d1d3e8ab7aa2f3ae4.tar.gz |
use malloc() instead of calloc().
Here malloc() is enough because all elements of the page_list
will be overwrite.
-rw-r--r-- | gc.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -7570,14 +7570,18 @@ typedef int page_compare_func_t(const void *, const void *, void *); static struct heap_page ** allocate_page_list(rb_objspace_t *objspace, page_compare_func_t *comparator) { - size_t n = heap_eden->total_pages; - struct heap_page *page, **page_list = calloc(n, sizeof(struct heap_page *)); + size_t total_pages = heap_eden->total_pages; + struct heap_page *page, **page_list = malloc(total_pages * sizeof(struct heap_page *)); int i = 0; list_for_each(&heap_eden->pages, page, page_node) { page_list[i++] = page; + GC_ASSERT(page != NULL); } - ruby_qsort(page_list, n, sizeof(struct heap_page *), comparator, NULL); + GC_ASSERT(total_pages > 0); + GC_ASSERT((size_t)i == total_pages); + + ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), comparator, NULL); return page_list; } |