8353329: Small memory leak when create GrowableArray with initial size 0

Reviewed-by: jsjolen, stefank
This commit is contained in:
Zhengyu Gu 2025-04-02 11:56:53 +00:00
parent 4a50778a26
commit b80b04d77a
2 changed files with 6 additions and 5 deletions

View File

@ -43,6 +43,11 @@ void* GrowableArrayArenaAllocator::allocate(int max, int element_size, Arena* ar
void* GrowableArrayCHeapAllocator::allocate(int max, int element_size, MemTag mem_tag) {
assert(max >= 0, "integer overflow");
if (max == 0) {
return nullptr;
}
size_t byte_size = element_size * (size_t) max;
// memory tag has to be specified for C heap allocation

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -811,10 +811,6 @@ class GrowableArrayCHeap : public GrowableArrayWithAllocator<E, GrowableArrayCHe
STATIC_ASSERT(MT != mtNone);
static E* allocate(int max, MemTag mem_tag) {
if (max == 0) {
return nullptr;
}
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), mem_tag);
}