KEMBAR78
Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime by krk · Pull Request #1351 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

@krk
Copy link
Contributor

@krk krk commented Jun 25, 2025

Initialize buf in getTotalCpuTime, to avoid any possibility of sscanf reading uninitialized data.

Also pass the minimum valid alignment, which is sizeof(void*) to the posix_memalign call in mallocTracer initialization. glibc is lenient in this case, we should still call it with a valid alignment.

How has this been tested?

make test


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

void* p3 = aligned_alloc(1, 1);
void* p4 = NULL;
if (posix_memalign(&p4, 1, 1) == 0) free(p4);
if (posix_memalign(&p4, sizeof(void*), 1) == 0) free(p4);
Copy link
Member

Choose a reason for hiding this comment

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

Let allocation size match alignment?

Copy link
Contributor Author

@krk krk Jun 26, 2025

Choose a reason for hiding this comment

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

Will do.

src/os_linux.cpp Outdated

u64 real = (u64)-1;
char buf[512];
char buf[512] = {0};
Copy link
Member

Choose a reason for hiding this comment

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

Can you shrink buffer to the minimum required size? I think 128 will be good.
It did not make difference for uninitialized buffer, but should reduce amount of work for zeroing.

krk and others added 3 commits June 26, 2025 15:46
Signed-off-by: Andrei Pangin <1749416+apangin@users.noreply.github.com>
@apangin apangin merged commit 5b4450b into async-profiler:master Jun 26, 2025
6 checks passed
visheshruparelia pushed a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
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.

2 participants