Skip to content

C API memory leak Asan #29049

Description

@KilLogic98

Describe the issue

I'm a rookie with ONNX Runtime. – this issue is urgent for my development. Your prompt reply would be much appreciated.

When repeatedly creating and releasing an OrtEnv (calling CreateEnv and ReleaseEnv in a loop), the program does not free all allocated memory. AddressSanitizer (LeakSanitizer) reports a small but persistent leak of 144 bytes (3 allocations) per iteration or in total, depending on the test.

[root@localhost build]# ./minimal_leak_test
Completed 10 iterations without crash.

=================================================================
==231965==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 1 object(s) allocated from:
#0 0xffffb8fe91f0 in __interceptor_calloc (/usr/lib64/libasan.so.6+0xa51f0)
#1 0xffffb8b56af8 (/usr/lib64/libonnxruntime.so.1.17.0+0x819af8)
#2 0xffffb8211dac (/usr/lib64/libc.so.6+0x83dac)
#3 0xffffb8450f8c (/usr/lib64/libonnxruntime.so.1.17.0+0x113f8c)
#4 0xffffb8451eb4 (/usr/lib64/libonnxruntime.so.1.17.0+0x114eb4)
#5 0xffffb83f4164 (/usr/lib64/libonnxruntime.so.1.17.0+0xb7164)
#6 0xffffb83c215c (/usr/lib64/libonnxruntime.so.1.17.0+0x8515c)
#7 0x400b98 in main /opt/SQL/leak/build/minimal_leak_test.c:14
#8 0xffffb81b9038 (/usr/lib64/libc.so.6+0x2b038)
#9 0xffffb81b9110 in __libc_start_main (/usr/lib64/libc.so.6+0x2b110)
#10 0x40096c in _start (/opt/SQL/leak/build/minimal_leak_test+0x40096c)

Direct leak of 64 byte(s) in 1 object(s) allocated from:
#0 0xffffb8fe91f0 in __interceptor_calloc (/usr/lib64/libasan.so.6+0xa51f0)
#1 0xffffb8b56ae4 (/usr/lib64/libonnxruntime.so.1.17.0+0x819ae4)
#2 0xffffb8211dac (/usr/lib64/libc.so.6+0x83dac)
#3 0xffffb8450f8c (/usr/lib64/libonnxruntime.so.1.17.0+0x113f8c)
#4 0xffffb8451eb4 (/usr/lib64/libonnxruntime.so.1.17.0+0x114eb4)
#5 0xffffb83f4164 (/usr/lib64/libonnxruntime.so.1.17.0+0xb7164)
#6 0xffffb83c215c (/usr/lib64/libonnxruntime.so.1.17.0+0x8515c)
#7 0x400b98 in main /opt/SQL/leak/build/minimal_leak_test.c:14
#8 0xffffb81b9038 (/usr/lib64/libc.so.6+0x2b038)
#9 0xffffb81b9110 in __libc_start_main (/usr/lib64/libc.so.6+0x2b110)
#10 0x40096c in _start (/opt/SQL/leak/build/minimal_leak_test+0x40096c)

Direct leak of 16 byte(s) in 1 object(s) allocated from:
#0 0xffffb8fe91f0 in __interceptor_calloc (/usr/lib64/libasan.so.6+0xa51f0)
#1 0xffffb8b56ad0 (/usr/lib64/libonnxruntime.so.1.17.0+0x819ad0)
#2 0xffffb8211dac (/usr/lib64/libc.so.6+0x83dac)
#3 0xffffb8450f8c (/usr/lib64/libonnxruntime.so.1.17.0+0x113f8c)
#4 0xffffb8451eb4 (/usr/lib64/libonnxruntime.so.1.17.0+0x114eb4)
#5 0xffffb83f4164 (/usr/lib64/libonnxruntime.so.1.17.0+0xb7164)
#6 0xffffb83c215c (/usr/lib64/libonnxruntime.so.1.17.0+0x8515c)
#7 0x400b98 in main /opt/SQL/leak/build/minimal_leak_test.c:14
#8 0xffffb81b9038 (/usr/lib64/libc.so.6+0x2b038)
#9 0xffffb81b9110 in __libc_start_main (/usr/lib64/libc.so.6+0x2b110)
#10 0x40096c in _start (/opt/SQL/leak/build/minimal_leak_test+0x40096c)

SUMMARY: AddressSanitizer: 144 byte(s) leaked in 3 allocation(s).

To reproduce

// minimal_leak_test.c
#include <onnxruntime_c_api.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
const OrtApiBase* api_base = OrtGetApiBase();
const OrtApi* ort = api_base->GetApi(ORT_API_VERSION);
const int iterations = 10;
for (int i = 0; i < iterations; ++i) {
OrtEnv* env = NULL;
OrtStatus* status = ort->CreateEnv(ORT_LOGGING_LEVEL_WARNING, "test", &env);
if (status) {
fprintf(stderr, "CreateEnv failed at iteration %d\n", i);
ort->ReleaseStatus(status);
return 1;
}
ort->ReleaseEnv(env);
}
printf("Completed %d iterations without crash.\n", iterations);
return 0;
}

gcc -g -fsanitize=address -I../include minimal_leak_test.c -L../lib -lonnxruntime -o minimal_leak_test ./minimal_leak_test

Urgency

urgent

Platform

Linux

OS Version

GNU

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.16.0-1.22.0

ONNX Runtime API

C

Architecture

ARM64

Execution Provider

Other / Unknown

Execution Provider Library Version

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions