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

std::move causes segmentation fault in TF_DeleteSession () from /usr/local/lib/libtensorflow.so.2 #254

Open
k-maheshkumar opened this issue Nov 28, 2023 · 1 comment

Comments

@k-maheshkumar
Copy link

k-maheshkumar commented Nov 28, 2023

Moving cppflow::model causes segmentation fault on desctruction similar to #132, #154. Btw, this will happen to all default constructor implementations.

#include <cppflow/model.h>
#include <iostream>

// to run: ./example2 /path/to/model

class ModelInference
{
public:
    explicit ModelInference(cppflow::model&& _model) : model{std::move(_model)} {}
private:
    cppflow::model model;
};

int main(int, char* argv[])
{
    const std::string modelPath{argv[1]};
    ModelInference modelInference{cppflow::model{modelPath}};
    std::cout << "all ok exiting" << std::endl;
    return 0;
}

Please find the example to reproduce the problem at cppflow.zip

Gdb backtrace:

[New Thread 0x7ffea5ffb640 (LWP 16486)]
[Thread 0x7ffea5ffb640 (LWP 16486) exited]
2023-11-28 13:42:00.067943: I tensorflow/cc/saved_model/loader.cc:215] Running initialization op on SavedModel bundle at path: ../model/
2023-11-28 13:42:00.072693: I tensorflow/cc/saved_model/loader.cc:314] SavedModel load for tags { serve }; Status: success: OK. Took 339877 microseconds.
all ok exiting

Thread 1 "example2" received signal SIGSEGV, Segmentation fault.
0x00007fffced60a7d in TF_DeleteSession () from /usr/local/lib/libtensorflow.so.2
(gdb) bt
#0  0x00007fffced60a7d in TF_DeleteSession () from /usr/local/lib/libtensorflow.so.2
#1  0x000055555555b2b7 in cppflow::model::model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cppflow::model::TYPE)::{lambda(TF_Session*)#1}::operator()(TF_Session*) const ()
#2  0x000055555555ecac in std::_Sp_counted_deleter<TF_Session*, cppflow::model::model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cppflow::model::TYPE)::{lambda(TF_Session*)#1}, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() ()
#3  0x000055555555b083 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
#4  0x000055555555bd79 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() ()
#5  0x000055555555b25e in std::__shared_ptr<TF_Session, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() ()
#6  0x000055555555b27e in std::shared_ptr<TF_Session>::~shared_ptr() ()
#7  0x000055555555bb4e in cppflow::model::~model() ()
#8  0x000055555555bbc2 in ModelInference::~ModelInference() ()
#9  0x000055555555add7 in main ()
(gdb) bt
#0  0x00007fffced60a7d in TF_DeleteSession () from /usr/local/lib/libtensorflow.so.2
#1  0x000055555555b2b7 in cppflow::model::model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cppflow::model::TYPE)::{lambda(TF_Session*)#1}::operator()(TF_Session*) const ()
#2  0x000055555555ecac in std::_Sp_counted_deleter<TF_Session*, cppflow::model::model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cppflow::model::TYPE)::{lambda(TF_Session*)#1}, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() ()
#3  0x000055555555b083 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
#4  0x000055555555bd79 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() ()
#5  0x000055555555b25e in std::__shared_ptr<TF_Session, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() ()
#6  0x000055555555b27e in std::shared_ptr<TF_Session>::~shared_ptr() ()
#7  0x000055555555bb4e in cppflow::model::~model() ()
#8  0x000055555555bbc2 in ModelInference::~ModelInference() ()
#9  0x000055555555add7 in main ()

@adayton1
Copy link

adayton1 commented Jun 7, 2024

Just remove the call to std::move. You already have an rvalue reference, so the move constructor will get called without an additional call to std::move.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants