RFR: 8259623: JfrTypeSet::_subsystem_callback is left dangling after use
Markus Grönlund
mgronlun at openjdk.java.net
Thu Mar 25 14:41:27 UTC 2021
On Thu, 25 Mar 2021 13:15:26 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
> SonarCloud instance reports the bug in cases like:
> "Address of stack memory associated with local variable 'callback' is still referred to by the global variable '_subsystem_callback' upon returning to the caller. This will be a dangling reference"
>
> For example:
>
> static void clear_packages() {
> ClearArtifact<PkgPtr> clear;
> ClearPackageCallback callback(&clear);
> _subsystem_callback = &callback;
> do_packages();
> }
>
> I understand that `_subsystem_callback` is assigned to be used in do_packages(), but it would indeed be left dangling. The patch moves callback installation into the callback superclass itself. This way, we also guarantee that `_subsystem_callback` is not set before installation (i.e. check for overlapping callback installations), and make sure it is `NULL` after use.
Looks good, Thanks.
-------------
Marked as reviewed by mgronlun (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/3192
More information about the hotspot-jfr-dev
mailing list