Skip to content

Memory leak in cpuinfo_x86_linux_init #16117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jrosdahl opened this issue May 26, 2023 · 3 comments
Open

Memory leak in cpuinfo_x86_linux_init #16117

jrosdahl opened this issue May 26, 2023 · 3 comments
Labels
core runtime issues related to core runtime

Comments

@jrosdahl
Copy link

jrosdahl commented May 26, 2023

Describe the issue

When using ONNX Runtime 1.14.1 with a Linux C++ program built with GCC's -fsanitize=leak option (LeakSanitizer AKA LSan) or -fsanitize=address (AddressSanitizer AKA ASan), memory leaks are reported at program exit:

=================================================================
==11753==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 576 byte(s) in 1 object(s) allocated from:
    #0 0x2b11dd429917 in __interceptor_calloc (/path/to/libasan.so.6+0xb4917)
    #1 0x2b11e45064b6 in cpuinfo_x86_linux_init (/path/to/libonnxruntime.so.1.14.1+0x8684b6)

Direct leak of 576 byte(s) in 1 object(s) allocated from:
    #0 0x2b11dd429917 in __interceptor_calloc (/path/to/libasan.so.6+0xb4917)
    #1 0x2b11e4506496 in cpuinfo_x86_linux_init (/path/to/libonnxruntime.so.1.14.1+0x868496)

SUMMARY: AddressSanitizer: 1152 byte(s) leaked in 2 allocation(s).

From code inspection, is seems that the call to cpuinfo_initialize does not seem to have a corresponding call to cpuinfo_deinitialize. On the other hand, cpuinfo_deinitialize doesn't actually free the allocated memory so it wouldn't have helped. Reported in pytorch/cpuinfo#150.

Still, the memory leaks show up as a problem for ONNX Runtime users who run their programs with LeakSanitizer and flag memory leaks as errors in CI pipelines and the like, so it would be great if it could be resolved even if the issue certainly could be considered minor for most users.

To reproduce

  1. Create an ONNX Runtime program with GCC's -fsanitize=leak or -fsanitize=address options.
  2. Execute it.
  3. Check the memory leak report printed to stderr.

I don't have a minimal reproducible example at hand right now, but I can try to make one on request.

Urgency

No response

Platform

Linux

OS Version

CentOS 7.9

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.14.1

ONNX Runtime API

C++

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@snnn
Copy link
Member

snnn commented May 26, 2023

I will make a quick fix.

@snnn
Copy link
Member

snnn commented May 26, 2023

It seems not easy. It is related to #15661 . I will talk to the devs in @onnxruntime-mlas team , I suggest adding an initialize function to mlas so that I can call it in Environment::Initialize() function. And the initialization happens after initialize cpuinfo. And the functions in WindowsEnv should return Status instead of use loggers. Callers of the functions can decide when to print out.

@snnn
Copy link
Member

snnn commented May 26, 2023

If we call cpuinfo_initialize in Environment class's constructor, we can call the cpuinfo_deinitialize in its destructor. Then there will not be any memory leak if cpuinfo_deinitialize works as expected

@yf711 yf711 added the core runtime issues related to core runtime label Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core runtime issues related to core runtime
Projects
None yet
Development

No branches or pull requests

3 participants