Skip to content

Conversation

@edgchen1
Copy link
Contributor

@edgchen1 edgchen1 commented Apr 25, 2025

Description

Fix memleakdbg call stack output.

The call stack output was getting clobbered:
C:\dev\onnxruntime\build\Debug\_deps\googletest-src\googletest\include\gtest\internal\gtest-port.h(1631): l\gtest-port.h(1631): eadLocal<testing::Sequence *>::GetOrCreateValue

I think the issue is that this aliasing of buffer and symbol:

alignas(SYMBOL_INFO) char buffer[kInitialBufferSize] = {0};
SYMBOL_INFO* symbol = reinterpret_cast<SYMBOL_INFO*>(buffer);
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME;

does not play nicely with a call to _snprintf_s like this:

_snprintf_s(buffer, _TRUNCATE, "%s(%d): %s", line.FileName, static_cast<int>(line.LineNumber), symbol->Name);

The clobbered output does not match the predefined, ignored patterns, so we see spurious mem leak check output.

This change updates the memleakdbg output generation to use C++ ostreams and instead of fixed size buffers and _snprintf_s.

Motivation and Context

Fix spurious mem leak check output.
Fix #24535.

@edgchen1 edgchen1 merged commit d4c9b92 into main Apr 25, 2025
87 of 89 checks passed
@edgchen1 edgchen1 deleted the edgchen1/fix_debug_alloc_callstack branch April 25, 2025 23:32
vraspar pushed a commit that referenced this pull request Apr 29, 2025
### Description
<!-- Describe your changes. -->

Fix memleakdbg call stack output.

The call stack output was getting clobbered:

`C:\dev\onnxruntime\build\Debug\_deps\googletest-src\googletest\include\gtest\internal\gtest-port.h(1631):
l\gtest-port.h(1631): eadLocal<testing::Sequence *>::GetOrCreateValue`

I think the issue is that this aliasing of `buffer` and `symbol`:

https://github.com/microsoft/onnxruntime/blob/173a11a4e7a2f7a360c9db6abbe601a06a16f004/onnxruntime/core/platform/windows/debug_alloc.cc#L97-L100

does not play nicely with a call to `_snprintf_s` like this:

https://github.com/microsoft/onnxruntime/blob/173a11a4e7a2f7a360c9db6abbe601a06a16f004/onnxruntime/core/platform/windows/debug_alloc.cc#L115

The clobbered output does not match the predefined, ignored patterns, so
we see spurious mem leak check output.

This change updates the memleakdbg output generation to use C++ ostreams
and instead of fixed size buffers and `_snprintf_s`.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Fix spurious mem leak check output.
Fix #24535.
jywu-msft pushed a commit that referenced this pull request Apr 30, 2025
### Description

Cherry pick the following into
[rel-1.22.0](https://github.com/microsoft/onnxruntime/tree/rel-1.22.0)


- (#24487)
- (#24466)
- (#24493)
- (#24484)
- (#24494)
- (#24489)
- (#24504)
- (#24510)
- (#24456)
- (#24537)
- (#24501)
- (#24519)
- (#24513)
- (#24539)
- (#24514)
- (#24542)
- (#24585)

Not added:

Planning to cherry pick Cuda Matmulnbits PRs once the fix for failing
cuda pipeline is ready
- (#24491)
- (#24509)
- (#24564)

---------

Co-authored-by: Adrian Lizarraga <[email protected]>
Co-authored-by: minfhong-quic <[email protected]>
Co-authored-by: minfhong-quic <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Co-authored-by: Prathik Rao <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
Co-authored-by: Ankan Banerjee <[email protected]>
Co-authored-by: Maximilian Müller <[email protected]>
Co-authored-by: Gaurav Garg <[email protected]>
Co-authored-by: iraut <[email protected]>
Co-authored-by: Hrishikesh Manohar <[email protected]>
Co-authored-by: Maximilian Müller <[email protected]>
Co-authored-by: Scott McKay <[email protected]>
Co-authored-by: Jiajia Qin <[email protected]>
Co-authored-by: kunal-vaishnavi <[email protected]>
Co-authored-by: xhcao <[email protected]>
jatinwadhwa921 pushed a commit to intel/onnxruntime that referenced this pull request Apr 30, 2025
### Description

Cherry pick the following into
[rel-1.22.0](https://github.com/microsoft/onnxruntime/tree/rel-1.22.0)


- (microsoft#24487)
- (microsoft#24466)
- (microsoft#24493)
- (microsoft#24484)
- (microsoft#24494)
- (microsoft#24489)
- (microsoft#24504)
- (microsoft#24510)
- (microsoft#24456)
- (microsoft#24537)
- (microsoft#24501)
- (microsoft#24519)
- (microsoft#24513)
- (microsoft#24539)
- (microsoft#24514)
- (microsoft#24542)
- (microsoft#24585)

Not added:

Planning to cherry pick Cuda Matmulnbits PRs once the fix for failing
cuda pipeline is ready
- (microsoft#24491)
- (microsoft#24509)
- (microsoft#24564)

---------

Co-authored-by: vraspar <[email protected]>
Co-authored-by: Adrian Lizarraga <[email protected]>
Co-authored-by: minfhong-quic <[email protected]>
Co-authored-by: minfhong-quic <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Co-authored-by: Prathik Rao <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
Co-authored-by: Ankan Banerjee <[email protected]>
Co-authored-by: Maximilian Müller <[email protected]>
Co-authored-by: Gaurav Garg <[email protected]>
Co-authored-by: iraut <[email protected]>
Co-authored-by: Hrishikesh Manohar <[email protected]>
Co-authored-by: Maximilian Müller <[email protected]>
Co-authored-by: Scott McKay <[email protected]>
Co-authored-by: Jiajia Qin <[email protected]>
Co-authored-by: kunal-vaishnavi <[email protected]>
Co-authored-by: xhcao <[email protected]>
ankitm3k pushed a commit to intel/onnxruntime that referenced this pull request May 12, 2025
### Description
<!-- Describe your changes. -->

Fix memleakdbg call stack output.

The call stack output was getting clobbered:

`C:\dev\onnxruntime\build\Debug\_deps\googletest-src\googletest\include\gtest\internal\gtest-port.h(1631):
l\gtest-port.h(1631): eadLocal<testing::Sequence *>::GetOrCreateValue`

I think the issue is that this aliasing of `buffer` and `symbol`:

https://github.com/microsoft/onnxruntime/blob/173a11a4e7a2f7a360c9db6abbe601a06a16f004/onnxruntime/core/platform/windows/debug_alloc.cc#L97-L100

does not play nicely with a call to `_snprintf_s` like this:

https://github.com/microsoft/onnxruntime/blob/173a11a4e7a2f7a360c9db6abbe601a06a16f004/onnxruntime/core/platform/windows/debug_alloc.cc#L115

The clobbered output does not match the predefined, ignored patterns, so
we see spurious mem leak check output.

This change updates the memleakdbg output generation to use C++ ostreams
and instead of fixed size buffers and `_snprintf_s`.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Fix spurious mem leak check output.
Fix microsoft#24535.
samwebster added a commit that referenced this pull request Jun 10, 2025
@snnn
Copy link
Member

snnn commented Sep 5, 2025

This PR has been included in the rel-1.22.0 branch. Removing the release:1.22.0 label.

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.

ORT Debug Build Fails to Infer for Every Model

5 participants