Fix memory leak in JfrMetadata::reset() - #694
Draft
jbachorik wants to merge 1 commit into
Draft
Conversation
reset() cleared _root._children/_attributes without deleting the heap-allocated Element/NoField objects initialize() had allocated. Only reachable via a Profiler restart (reset() -> initialize() a second time in the same process); unrelated to PROF-15075, which crashes on a plain chunk dump with no restart involved (split out of #692 per https://datadoghq.atlassian.net/browse/PROF-15075).
3 tasks
Contributor
CI Test ResultsRun: #30355775898 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-07-28 12:14:17 UTC |
Contributor
Benchmark Results (commit 008d688)Pipeline: https://gitlab.ddbuild.io/DataDog/apm-reliability/benchmarking-platform/-/pipelines/127401287 Commit:
|
| Benchmark | JDK | Latest | Dev | Δ (dev vs latest) | Issues L/D |
|---|---|---|---|---|---|
| akka-uct | 21 | ✅ 10193 ms (21 iters) | ✅ 10416 ms (21 iters) | ≈ +2.2% (±11.2%) | — / — |
| akka-uct | 25 | ✅ 8880 ms (24 iters) | ✅ 8743 ms (24 iters) | ≈ -1.5% (±10%) | — / — |
| finagle-chirper | 21 | ✅ 6002 ms (33 iters) | ✅ 5929 ms (33 iters) | ≈ -1.2% (±24.7%) | |
| finagle-chirper | 25 | ✅ 5437 ms (36 iters) | ✅ 5445 ms (36 iters) | ≈ +0.1% (±24.3%) | |
| fj-kmeans | 21 | ✅ 2745 ms (68 iters) | ✅ 2638 ms (72 iters) | 🟢 -3.9% | — / — |
| fj-kmeans | 25 | ✅ 2832 ms (66 iters) | ✅ 2832 ms (66 iters) | ≈ 0% (±2.6%) | — / — |
| future-genetic | 21 | ✅ 2122 ms (87 iters) | ✅ 2058 ms (90 iters) | 🟢 -3% | — / — |
| future-genetic | 25 | ✅ 2059 ms (90 iters) | ✅ 2049 ms (90 iters) | ≈ -0.5% (±2.6%) | — / — |
| naive-bayes | 21 | ✅ 1257 ms (136 iters) | ✅ 1304 ms (132 iters) | ≈ +3.7% (±33.1%) | — / — |
| naive-bayes | 25 | ✅ 1028 ms (167 iters) | ✅ 1014 ms (169 iters) | ≈ -1.4% (±31.8%) | — / — |
| reactors | 21 | ✅ 16668 ms (15 iters) | ✅ 15846 ms (15 iters) | ≈ -4.9% (±7.4%) | — / — |
| reactors | 25 | ✅ 18281 ms (15 iters) | ✅ 18391 ms (15 iters) | ≈ +0.6% (±5%) | — / — |
Internal counter details (ddprof)
ddprof internal counters, latest / dev (✅ = 0, · = unavailable):
| Benchmark | JDK | Dropped rec | Dropped jvmti | Dropped trace | Skipped WC | AGCT fail | Unwind fail |
|---|---|---|---|---|---|---|---|
| akka-uct | 21 | ✅ / ✅ | ✅ / ✅ | 4 / 2 | 1961 / 1939 | ✅ / ✅ | ✅ / ✅ |
| akka-uct | 25 | ✅ / ✅ | ✅ / ✅ | 6 / 1 | 2369 / 2031 | ✅ / ✅ | ✅ / ✅ |
| finagle-chirper | 21 | ✅ / ✅ | ✅ / ✅ | 4 / 1 | 8227 / 8628 | ✅ / ✅ | ✅ / ✅ |
| finagle-chirper | 25 | ✅ / ✅ | ✅ / ✅ | ✅ / ✅ | 8367 / 8248 | ✅ / ✅ | ✅ / ✅ |
| fj-kmeans | 21 | ✅ / ✅ | ✅ / ✅ | 2 / 1 | 1267 / 1276 | ✅ / ✅ | ✅ / ✅ |
| fj-kmeans | 25 | ✅ / ✅ | ✅ / ✅ | ✅ / ✅ | 1287 / 1259 | ✅ / ✅ | ✅ / ✅ |
| future-genetic | 21 | ✅ / ✅ | ✅ / ✅ | 2 / 1 | 2932 / 3002 | ✅ / ✅ | ✅ / ✅ |
| future-genetic | 25 | ✅ / ✅ | ✅ / ✅ | 2 / 2 | 2843 / 2845 | ✅ / ✅ | ✅ / ✅ |
| naive-bayes | 21 | ✅ / ✅ | ✅ / ✅ | 2 / 4 | 3484 / 3550 | ✅ / ✅ | ✅ / ✅ |
| naive-bayes | 25 | ✅ / ✅ | ✅ / ✅ | 2 / 4 | 3492 / 3488 | ✅ / ✅ | ✅ / ✅ |
| reactors | 21 | ✅ / ✅ | ✅ / ✅ | 1 / 2 | 1638 / 1621 | ✅ / ✅ | ✅ / ✅ |
| reactors | 25 | ✅ / ✅ | ✅ / ✅ | 1 / 1 | 1843 / 1824 | ✅ / ✅ | ✅ / ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?:
JfrMetadata::reset()cleared_root._children/_root._attributeswithout deleting the heap-allocatedElement/NoFieldobjectsinitialize()had allocated, leaking them and leaving the tree vulnerable to use-after-free if the allocator later reused a freed address. Adds recursive deletion of theElementtree and the tracked_nofieldslist before clearing.Motivation:
Only reachable via a profiler restart (
reset()followed byinitialize()a second time in the same process). Found while investigating PROF-15075 (SIGSEGV inRecording::writeElement) but not its cause — that crash trace shows a plain chunk dump with no restart involved. Closing this separately since it's a real leak/UAF risk on its own.How to test the change?:
ddprof-lib/src/test/cpp/jfrMetadata_ut.cppexercisesinitialize()/reset()cycles, including with context attributes, and asserts no leaked/danglingElements.For Datadog employees:
credentials of any kind, I've requested a security review (run the
dd:platform-security-reviewskill, or file a request via the PSEC review form).
bewairealso runs automatically on every PR.Unsure? Have a question? Request a review!