Skip to content

fix: memory leaks, integer truncation, UB, and double-stop#26

Merged
JonasBa merged 1 commit into
mainfrom
fix/native-bindings-bugs
Apr 30, 2026
Merged

fix: memory leaks, integer truncation, UB, and double-stop#26
JonasBa merged 1 commit into
mainfrom
fix/native-bindings-bugs

Conversation

@JonasBa
Copy link
Copy Markdown
Member

@JonasBa JonasBa commented Apr 30, 2026

Fix a couple bugs that claude found in the cpu profiler

…ble-stop in cpu_profiler

- Replace malloc with std::string in StartProfiling, StopProfiling, and
  GetFrameModuleWrapped to fix memory leaks on every call (RAII handles
  cleanup on all return paths)
- Cast uint64_t to double before division in cpu_callback to preserve
  fractional precision in CPU usage stats
- Stop and delete profiles inline in FreeAddonData then clear() the map,
  instead of calling CleanupSentryProfile which erases during iteration
  (undefined behavior on std::unordered_map)
- Guard SentryProfile::Stop with a status check to make it idempotent,
  preventing double-stop when callers call Stop() before CleanupSentryProfile

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread bindings/cpu_profiler.cc
size_t len;
assert(napi_get_value_string_utf8(env, argv[0], NULL, 0, &len) == napi_ok);

char *abs_path = (char *)malloc(len + 1);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was leaking the title

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lol

@JonasBa JonasBa merged commit 5069626 into main Apr 30, 2026
66 checks passed
mydea added a commit to getsentry/sentry-javascript that referenced this pull request May 8, 2026
…4.0 (#20720)

Bumps this from 2.2.0 to 2.4.0, including the following changes:

## v2.4.0

* feat: Add Node 26 support
(getsentry/sentry-javascript-profiling-node-binaries#32)

## v2.3.0

* fix: Memory leaks, integer truncation, UB, and double-stop
(getsentry/sentry-javascript-profiling-node-binaries#26)
* fix: Integer arithmetic for timestamps, emit elapsed_since_start_ns as
string
(getsentry/sentry-javascript-profiling-node-binaries#28)
* fix: Dead member, capacity checks, insert perf, napi_env by value
(getsentry/sentry-javascript-profiling-node-binaries#27)
* chore: Replace execSync with execFileSync to prevent command injection
(getsentry/sentry-javascript-profiling-node-binaries#23)
* chore: Pin GitHub Actions to full-length commit SHAs
(getsentry/sentry-javascript-profiling-node-binaries#24)
* ci: Build Linux in container for wider glibc support
(getsentry/sentry-javascript-profiling-node-binaries#16)
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.

3 participants