Skip to content
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

[Mobile] [urgent] iOS application crash at CreateEnv (pointer being freed was not allocated) #23759

Open
Consulting4J opened this issue Feb 20, 2025 · 3 comments
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@Consulting4J
Copy link

Describe the issue

with bridge iOS application would call the following c code

OrtEnv *env;
OrtSession *session;
OrtSessionOptions *session_options;
const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
g_ort->CreateEnv(ORT_LOGGING_LEVEL_FATAL, "", &env);
g_ort->CreateSessionOptions(&session_options);

while try to run this application on device got the following error:

malloc: *** error for object 0x3293902a: pointer being freed was not allocated

this onnxruntime libs were build by the following steps:
https://onnxruntime.ai/docs/build/ios.html

./build.sh --config MinSizeRel --use_xcode
--ios --apple_sysroot iphoneos --osx_arch arm64 --apple_deploy_target 15.0

device : iPhone pro max 13

any idea to solve such simple problem?
many thanks !

To reproduce

run the following code in any ios application:

OrtEnv *env;
OrtSession *session;
OrtSessionOptions *session_options;
const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
g_ort->CreateEnv(ORT_LOGGING_LEVEL_FATAL, "", &env);
g_ort->CreateSessionOptions(&session_options);

Urgency

yes this is urgent

Platform

iOS

OS Version

18.1

ONNX Runtime Installation

Built from Source

Compiler Version (if 'Built from Source')

apple clang 16.1

Package Name (if 'Released Package')

None

ONNX Runtime Version or Commit ID

v1.20.2

ONNX Runtime API

C++/C

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@Consulting4J Consulting4J added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Feb 20, 2025
@edgchen1
Copy link
Contributor

if you're building from source, you can try building with --config Debug and check what's happening in the debugger. it would be helpful to get a stacktrace.

@Consulting4J
Copy link
Author

Helllo,
This is the full stack

#0 0x00000001bb03fbbc in __pthread_kill ()
#1 0x00000001dbae0844 in pthread_kill ()
#2 0x000000018ae446ac in abort ()
#3 0x000000019197c9d8 in malloc_vreport ()
#4 0x000000019197cb88 in malloc_report ()
#5 0x0000000191962d00 in free ()
#6 0x000000010753f938 in google::protobuf::RepeatedField::~RepeatedField [inlined] at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/protobuf-src/src/google/protobuf/port.h:50
#7 0x000000010753f934 in google::protobuf::RepeatedField::~RepeatedField [inlined] at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/protobuf-src/src/google/protobuf/repeated_field.h:409
#8 0x000000010753f92c in google::protobuf::RepeatedField::~RepeatedField [inlined] at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/protobuf-src/src/google/protobuf/repeated_field.h:554
#9 0x000000010753f91c in google::protobuf::RepeatedField::~RepeatedField at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/protobuf-src/src/google/protobuf/repeated_field.h:546
#10 0x0000000107403ba0 in onnx::TensorProto::SharedDtor at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-build/onnx/onnx-ml.pb.cc:5121
#11 0x0000000107403cbc in onnx::TensorProto::~TensorProto [inlined] at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-build/onnx/onnx-ml.pb.cc:5115
#12 0x0000000107403c9c in onnx::TensorProto::~TensorProto at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-build/onnx/onnx-ml.pb.cc:5109
#13 0x0000000107745620 in onnx::FunctionBodyHelper::Const at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-src/onnx/defs/function.h:102
#14 0x0000000107743948 in onnx::GetOpSchemaonnx::MeanVarianceNormalization_Onnx_ver9 at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-src/onnx/defs/nn/old.cc:239
#15 0x000000010766a9ec in onnx::OpSet_Onnx_ver9::ForEachSchema at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-src/onnx/defs/operator_sets.h:483
#16 0x0000000107665564 in onnx::RegisterOnnxOperatorSetSchema [inlined] at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-src/onnx/defs/schema.h:1503
#17 0x0000000107665544 in onnx::RegisterOnnxOperatorSetSchema at /userxxx/onnxruntime/build/iOS/RelWithDebInfo/_deps/onnx-src/onnx/defs/operator_sets.h:1197
#18 0x00000001076652d0 in std::__1::__call_once_proxy[abi:ne180100]<std::__1::tuple<onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_deleteonnxruntime::logging::LoggingManager>, OrtThreadingOptions const*, bool)::$_0&&>> [inlined] at /userxxx/onnxruntime/onnxruntime/core/session/environment.cc:257
#19 0x0000000107664fec in std::__1::__call_once_proxy[abi:ne180100]<std::__1::tuple<onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_deleteonnxruntime::logging::LoggingManager>, OrtThreadingOptions const*, bool)::$_0&&>> [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/include/c++/v1/__type_traits/invoke.h:344
#20 0x0000000107664fec in std::__1::__call_once_proxy[abi:ne180100]<std::__1::tuple<onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_deleteonnxruntime::logging::LoggingManager>, OrtThreadingOptions const*, bool)::$_0&&>> [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/include/c++/v1/__mutex/once_flag.h:97
#21 0x0000000107664fec in std::__1::__call_once_proxy[abi:ne180100]<std::__1::tuple<onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_deleteonnxruntime::logging::LoggingManager>, OrtThreadingOptions const*, bool)::$_0&&>> [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/include/c++/v1/__mutex/once_flag.h:91
#22 0x0000000107664fec in std::__1::__call_once_proxy[abi:ne180100]<std::__1::tuple<onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_deleteonnxruntime::logging::LoggingManager>, OrtThreadingOptions const*, bool)::$_0&&>> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/include/c++/v1/__mutex/once_flag.h:118
#23 0x0000000198021c10 in std::__1::__call_once ()
#24 0x0000000107662374 in onnxruntime::Environment::Initialize [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/include/c++/v1/__mutex/once_flag.h:131
#25 0x0000000107662338 in onnxruntime::Environment::Initialize at /userxxx/onnxruntime/onnxruntime/core/session/environment.cc:224
#26 0x0000000107662080 in onnxruntime::Environment::Create at /userxxx/onnxruntime/onnxruntime/core/session/environment.cc:63
#27 0x00000001076b18b0 in OrtEnv::GetInstance at /userxxx/onnxruntime/onnxruntime/core/session/ort_env.cc:61
#28 0x000000010769cf2c in OrtApis::CreateEnv at /userxxx/onnxruntime/onnxruntime/core/session/onnxruntime_c_api.cc:133

specifically it seems onnxrumtime crash here

fn(GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, MeanVarianceNormalization)>());

anything wrong?
Thank you so much!

@Consulting4J
Copy link
Author

almost the same stacktrace as this one
#11446

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants