Skip to content

Commit b80b04d

Browse files
committed
8353329: Small memory leak when create GrowableArray with initial size 0
Reviewed-by: jsjolen, stefank
1 parent 4a50778 commit b80b04d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/hotspot/share/utilities/growableArray.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ void* GrowableArrayArenaAllocator::allocate(int max, int element_size, Arena* ar
4343

4444
void* GrowableArrayCHeapAllocator::allocate(int max, int element_size, MemTag mem_tag) {
4545
assert(max >= 0, "integer overflow");
46+
47+
if (max == 0) {
48+
return nullptr;
49+
}
50+
4651
size_t byte_size = element_size * (size_t) max;
4752

4853
// memory tag has to be specified for C heap allocation

src/hotspot/share/utilities/growableArray.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -811,10 +811,6 @@ class GrowableArrayCHeap : public GrowableArrayWithAllocator<E, GrowableArrayCHe
811811
STATIC_ASSERT(MT != mtNone);
812812

813813
static E* allocate(int max, MemTag mem_tag) {
814-
if (max == 0) {
815-
return nullptr;
816-
}
817-
818814
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), mem_tag);
819815
}
820816

0 commit comments

Comments
 (0)