[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: [OpenJDK 2D-Dev] RFR: 8263893: getPrinterNames() leaks nameArray if Java String allocation fails
From:       Alexey Ivanov <aivanov () openjdk ! java ! net>
Date:       2021-03-24 20:16:41
Message-ID: I2Uq9ru0x5WAgpyoPqtFIuS18FPQGwfvzYZ_xuRsGak=.89df713c-94cd-48b6-96ca-fc54ef16f3c7 () github ! com
[Download RAW message or body]

On Fri, 19 Mar 2021 22:31:48 GMT, Sergey Bylokhov <serb@openjdk.org> wrote:

> > If `JNU_NewStringPlatform` fails to allocate new Java String object for printer \
> > name, `std::bad_alloc` is thrown. The handler for the exception does not release \
> > the local reference to the `nameArray`, thus it will be leaked.
> 
> src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp line 178:
> 
> > 176:     } catch (std::bad_alloc&) {
> > 177:         delete [] pPrinterEnum;
> > 178:         if (nameArray != NULL) {
> 
> Not sure that we usually clean the local refs in the native JNI methods, that only \
> required in the native loop which are never returned to the java(I have check that \
> by the grep of env->NewObjectArray)

You're right. It's not required: all local refs are cleared when the JNI method \
exits. My reasoning was that `env->DeleteLocalRef(utf_str)` is called in the loop. \
Strictly, it's not required either. Yet if there's a large number of elements in the \
array, it could cause a problem.

I'm going to withdraw the PR as the fix is not necessary.

-------------

PR: https://git.openjdk.java.net/jdk/pull/3096


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic