summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-05-28 11:42:31 +0900
committerKoichi Sasada <ko1@atdot.net>2019-05-28 11:44:08 +0900
commitf3bddc103d6a9d6e679ab35d1d3e8ab7aa2f3ae4 (patch)
tree6b2a524a29b05f752b8d34624f13555ba4a462a5
parentf9401d5d44dd4ae69b6a14fcccd41c2810033986 (diff)
downloadruby-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.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index 4d92ede42a..c42d907df5 100644
--- a/gc.c
+++ b/gc.c
@@ -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;
}