serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
788 stars 178 forks source link

Memory Leak from AddressSanitizer when trying the example #147

Closed abdullah-saal closed 2 years ago

abdullah-saal commented 3 years ago

I have this basic docker file

FROM ubuntu:18.04

RUN apt-get update -y && apt-get install tar gcc g++ git cmake wget -y

COPY libtensorflow-cpu-linux-x86_64-2.3.1.tar.gz libtensorflow.tar.gz

RUN tar -C /usr/local -xzf libtensorflow.tar.gz && rm libtensorflow.tar.gz

RUN ldconfig

RUN git clone https://github.com/serizba/cppflow.git \
    && cd cppflow/examples/load_model \
    && mkdir build \
    && cd build \
    && cmake .. \
    && make \
    && ./example

Getting The following error.

=================================================================
==199==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f5ca6083448 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0448)
    #1 0x7f5c9bb2908a in tensorflow::RegisterXlaDeviceKernels(char const*, char const*) (/usr/local/lib/libtensorflow.so.2+0xc8208a)
    #2 0x7f5c9bb17cbe in tensorflow::XlaCpuDeviceFactory::CreateDevices(tensorflow::SessionOptions const&, std::string const&, std::vector<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> >, std::allocator<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> > > >*) (/usr/local/lib/libtensorflow.so.2+0xc70cbe)
    #3 0x7f5c991059c4 in tensorflow::DeviceFactory::AddDevices(tensorflow::SessionOptions const&, std::string const&, std::vector<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> >, std::allocator<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> > > >*) (/usr/local/lib/libtensorflow_framework.so.2+0x108b9c4)
    #4 0x7f5c9b9feacf in TFE_NewContext (/usr/local/lib/libtensorflow.so.2+0xb57acf)
    #5 0x56479a40757a in cppflow::context::context(TFE_ContextOptions*) (/cppflow/examples/load_model/build/example+0x757a)
    #6 0x56479a407177 in cppflow::get_global_context() (/cppflow/examples/load_model/build/example+0x7177)
    #7 0x56479a4071d6 in cppflow::context::get_context() (/cppflow/examples/load_model/build/example+0x71d6)
    #8 0x56479a4091d2 in cppflow::fill(cppflow::tensor const&, cppflow::tensor const&, TF_DataType) (/cppflow/examples/load_model/build/example+0x91d2)
    #9 0x56479a406627 in main (/cppflow/examples/load_model/build/example+0x6627)
    #10 0x7f5c9a536bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)

Indirect leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7f5ca6083448 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0448)
    #1 0x7f5c9bb28f40 in void std::vector<std::unique_ptr<tensorflow::kernel_factory::OpKernelRegistrar, std::default_delete<tensorflow::kernel_factory::OpKernelRegistrar> >, std::allocator<std::unique_ptr<tensorflow::kernel_factory::OpKernelRegistrar, std::default_delete<tensorflow::kernel_factory::OpKernelRegistrar> > > >::_M_emplace_back_aux<tensorflow::kernel_factory::OpKernelRegistrar*>(tensorflow::kernel_factory::OpKernelRegistrar*&&) (/usr/local/lib/libtensorflow.so.2+0xc81f40)
    #2 0x7f5c9bb2926a in tensorflow::RegisterXlaDeviceKernels(char const*, char const*) (/usr/local/lib/libtensorflow.so.2+0xc8226a)
    #3 0x7f5c9bb17cbe in tensorflow::XlaCpuDeviceFactory::CreateDevices(tensorflow::SessionOptions const&, std::string const&, std::vector<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> >, std::allocator<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> > > >*) (/usr/local/lib/libtensorflow.so.2+0xc70cbe)
    #4 0x7f5c991059c4 in tensorflow::DeviceFactory::AddDevices(tensorflow::SessionOptions const&, std::string const&, std::vector<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> >, std::allocator<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> > > >*) (/usr/local/lib/libtensorflow_framework.so.2+0x108b9c4)
    #5 0x7f5c9b9feacf in TFE_NewContext (/usr/local/lib/libtensorflow.so.2+0xb57acf)
    #6 0x56479a40757a in cppflow::context::context(TFE_ContextOptions*) (/cppflow/examples/load_model/build/example+0x757a)
    #7 0x56479a407177 in cppflow::get_global_context() (/cppflow/examples/load_model/build/example+0x7177)
    #8 0x56479a4071d6 in cppflow::context::get_context() (/cppflow/examples/load_model/build/example+0x71d6)
    #9 0x56479a4091d2 in cppflow::fill(cppflow::tensor const&, cppflow::tensor const&, TF_DataType) (/cppflow/examples/load_model/build/example+0x91d2)
    #10 0x56479a406627 in main (/cppflow/examples/load_model/build/example+0x6627)
    #11 0x7f5c9a536bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)

Indirect leak of 400 byte(s) in 400 object(s) allocated from:
    #0 0x7f5ca6083448 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0448)
    #1 0x7f5c9bb29136 in tensorflow::RegisterXlaDeviceKernels(char const*, char const*) (/usr/local/lib/libtensorflow.so.2+0xc82136)
    #2 0x7f5c9bb17cbe in tensorflow::XlaCpuDeviceFactory::CreateDevices(tensorflow::SessionOptions const&, std::string const&, std::vector<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> >, std::allocator<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> > > >*) (/usr/local/lib/libtensorflow.so.2+0xc70cbe)
    #3 0x7f5c991059c4 in tensorflow::DeviceFactory::AddDevices(tensorflow::SessionOptions const&, std::string const&, std::vector<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> >, std::allocator<std::unique_ptr<tensorflow::Device, std::default_delete<tensorflow::Device> > > >*) (/usr/local/lib/libtensorflow_framework.so.2+0x108b9c4)
    #4 0x7f5c9b9feacf in TFE_NewContext (/usr/local/lib/libtensorflow.so.2+0xb57acf)
    #5 0x56479a40757a in cppflow::context::context(TFE_ContextOptions*) (/cppflow/examples/load_model/build/example+0x757a)
    #6 0x56479a407177 in cppflow::get_global_context() (/cppflow/examples/load_model/build/example+0x7177)
    #7 0x56479a4071d6 in cppflow::context::get_context() (/cppflow/examples/load_model/build/example+0x71d6)
    #8 0x56479a4091d2 in cppflow::fill(cppflow::tensor const&, cppflow::tensor const&, TF_DataType) (/cppflow/examples/load_model/build/example+0x91d2)
    #9 0x56479a406627 in main (/cppflow/examples/load_model/build/example+0x6627)
    #10 0x7f5c9a536bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)

SUMMARY: AddressSanitizer: 4520 byte(s) leaked in 402 allocation(s).

When trying with libtensorflow-cpu-linux-x86_64-2.5.0, I don't get the error, but I need this version.

serizba commented 2 years ago

If the error depends on the libtensorflow version, that doesn't look like a cppflow error.