Git Product home page Git Product logo

Comments (5)

EricGeng avatar EricGeng commented on July 1, 2024 1

I tried the fns_candy_style_transfer example with -fsanitize=address compile option, this example has three memory leaks

Build script

gcc -o fns_candy_style_transfer fns_candy_style_transfer.c image_file_libpng.c -fsanitize=address -Iinclude -Llib -lonnxruntime -lpng -Wl,-rpath=lib

Error / Output

./fns_candy_style_transfer candy.onnx test.png test2.png cpu

=================================================================
==3953065==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1555200 byte(s) in 1 object(s) allocated from:
    #0 0x7fc3bf15b887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x556fe87576fb in chw_to_hwc (/home/gh/workspace/test/fns_candy_style_transfer/fns_candy_style_transfer+0x26fb)
    #2 0x556fe8758712 in run_inference (/home/gh/workspace/test/fns_candy_style_transfer/fns_candy_style_transfer+0x3712)
    #3 0x556fe875981e in main (/home/gh/workspace/test/fns_candy_style_transfer/fns_candy_style_transfer+0x481e)
    #4 0x7fc3bdfd3d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Direct leak of 1536 byte(s) in 1 object(s) allocated from:
    #0 0x7fc3bf15ba57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fc3bec3adf9  (lib/libonnxruntime.so.1.18.0+0xa2cdf9)

Direct leak of 1536 byte(s) in 1 object(s) allocated from:
    #0 0x7fc3bf15ba57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fc3bec3addd  (lib/libonnxruntime.so.1.18.0+0xa2cddd)

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

The memory leaks at 0xa2cdf9 and 0xa2cddd still exist.
The memory leak in the chw_to_hwc function occurs because the variable output_data is allocated using malloc but is not freed after its use. The suggested solution is to manually release the allocated memory when it is no longer needed by freeing the memory pointed to by output_data.

  float* output_tensor_data = NULL;
  ORT_ABORT_ON_ERROR(g_ort->GetTensorMutableData(output_tensor, (void**)&output_tensor_data));
  uint8_t* output_image_data = NULL;
  chw_to_hwc(output_tensor_data, 720, 720, &output_image_data);
  if (write_image_file(output_image_data, 720, 720, output_file) != 0) {
    ret = -1;
  }
  g_ort->ReleaseValue(output_tensor);
  g_ort->ReleaseValue(input_tensor);
  free(model_input);
  free(output_image_data); // Manually release the memory when it is no longer needed

from onnxruntime.

snnn avatar snnn commented on July 1, 2024 1

It might be a false alarm. I rebuilt the code with address sanitizer, then the alert is gone. You may also try it locally. The command I used was:

python3 tools/ci_build/build.py --config Release --build_dir /tmp/cpubuild2 --parallel --skip_submodule_sync --enable_address_sanitizer  --build_shared_lib

Then use the newly built libruntime.so to replace the one you got from our release page.

from onnxruntime.

snnn avatar snnn commented on July 1, 2024 1

The code change you suggested for fns_candy_style_transfer is good. We should take it.

from onnxruntime.

snnn avatar snnn commented on July 1, 2024

Could you try this example? https://github.com/microsoft/onnxruntime-inference-examples/tree/main/c_cxx/fns_candy_style_transfer
Does it have memory leak?

from onnxruntime.

EricGeng avatar EricGeng commented on July 1, 2024

It might be a false alarm. I rebuilt the code with address sanitizer, then the alert is gone. You may also try it locally. The command I used was:

python3 tools/ci_build/build.py --config Release --build_dir /tmp/cpubuild2 --parallel --skip_submodule_sync --enable_address_sanitizer  --build_shared_lib

Then use the newly built libruntime.so to replace the one you got from our release page.

Thanks a lot. I tried what you suggested locally, now I'm sure it was a false alarm.

from onnxruntime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.