Skip to content

Delete CodeCache copy assignment instead of fixing its leak - #995

Merged
zhengyu123 merged 3 commits into
mainfrom
zgu/prof-16667-codecache-assign-leak
Nov 13, 2026
Merged

zhengyu123 merged 3 commits into
mainfrom
zgu/prof-16667-codecache-assign-leak

Conversation

@zhengyu123

@zhengyu123 zhengyu123 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?:

  • Declares CodeCache::operator= as = delete and removes its definition.
  • Adds a static_assert(!std::is_copy_assignable<CodeCache>::value) to codeCache_ut.cpp.

Motivation:

CodeCache::operator= freed _blobs but did not call NativeFunc::destroy() on each blob's _name, unlike ~CodeCache(). Every assignment leaked the target's blob name strings.

Nothing assigns a CodeCache. A temporary = delete probe compiled the library and all gtest sources (macOS, debug) with no assignment found. A grep of ddprof-lib/src covers the Linux-only sources the macOS build skips.

Deleting the operator is safer than fixing it:

  • A future assignment fails to compile instead of leaking.
  • Plain removal is not enough. It would let the compiler generate a shallow operator=, which double-frees _blobs and the names. Only the std::atomic<bool> _published member blocks that today.

Additional Notes:

  • Ticket deviation. PROF-16667's design adds the destructor's per-blob destroy loop to operator=. This PR deletes the operator instead, so its acceptance criteria about an ASan leak test do not apply.
  • Behavior and cost. No runtime change. The copy constructor is unchanged and still deep-copies the names.
  • Review. Sphinx (standard) on the first commit: one Low finding (no guard against reintroducing operator=), fixed by the static_assert. /code-review medium on the two fix commits: Low findings only. Open, not fixed:
    • copyFrom() now has one caller, the copy constructor, and could be inlined.
    • The static_assert could live in codeCache.h, so non-test builds check it too.
    • The assert message could point to codeCache.h for the reason.
  • Human review. Recommended but light. The change is small and compile-checked. A reviewer should confirm that deleting rather than fixing the operator is acceptable.

How to test the change?:

  • Gradle gtestDebug_codeCache_ut and gtestRelease_codeCache_ut: 11/11 passed in each (macOS arm64).
  • Gradle :ddprof-lib:gtestDebug: 1153 tests passed, 0 failed (macOS arm64). Linux-only suites link no tests on macOS; CI covers them.
  • The static_assert fails the test build if CodeCache becomes copy-assignable again.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-16667

Unsure? Have a question? Request a review!

🤖 Generated with Claude Code

zhengyu123 and others added 3 commits November 13, 2026 14:45
CodeCache::operator= freed the blob array but not the blob name strings,
so every assignment leaked them. Nothing assigns a CodeCache, so delete
the operator rather than fix it. Declare it "= delete" so a future
assignment fails to compile instead of falling back to a shallow copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zhengyu123
zhengyu123 requested a review from a team as a code owner November 13, 2026 20:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:45:18.885867Z 7391412 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmccnms
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 21.1.8 (6ubuntu1)
Date:Fri Nov 13 20:43:59 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs2
Logic error
Dereference of null pointer1
Unused code
Dead initialization1

Filter Results by File

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead initializationreferenceChains.cppapplyOomRamp4971
Logic errorDereference of null pointerperfEvents_linux.cppunregisterThread72026

@datadog-prod-us1-5 datadog-prod-us1-5 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Deleting the unused assignment operator removes the leaking ownership path while preserving copy construction. The static assertion guards against accidentally restoring copy assignment.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 7391412

@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #43504024551 | Commit: 1ff8900 | Duration: 20m 40s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-11-13 21:06:12 UTC

@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 73914128

@zhengyu123
zhengyu123 merged commit 9903e8a into main Nov 13, 2026
124 checks passed
@zhengyu123
zhengyu123 deleted the zgu/prof-16667-codecache-assign-leak branch November 13, 2026 21:46
@github-actions github-actions Bot added this to the 1.53.0 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant