From b80b04d77afdb2a808e2c7f9268d8092eb16714e Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Wed, 2 Apr 2025 11:56:53 +0000 Subject: [PATCH] 8353329: Small memory leak when create GrowableArray with initial size 0 Reviewed-by: jsjolen, stefank --- src/hotspot/share/utilities/growableArray.cpp | 5 +++++ src/hotspot/share/utilities/growableArray.hpp | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/utilities/growableArray.cpp b/src/hotspot/share/utilities/growableArray.cpp index 2a550a3f8a0..6a1cb0b0414 100644 --- a/src/hotspot/share/utilities/growableArray.cpp +++ b/src/hotspot/share/utilities/growableArray.cpp @@ -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 diff --git a/src/hotspot/share/utilities/growableArray.hpp b/src/hotspot/share/utilities/growableArray.hpp index 5dec089a4fb..31e797fc192 100644 --- a/src/hotspot/share/utilities/growableArray.hpp +++ b/src/hotspot/share/utilities/growableArray.hpp @@ -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