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

Double free corruption when chai is used both in a shared object and an executable linking to it #216

Open
sframba opened this issue Sep 28, 2022 · 0 comments

Comments

@sframba
Copy link

sframba commented Sep 28, 2022

Hi,
I don't know if this is a potential issue or simply a misuse of the library. When I have a a shared object and a main executable, both compiling against (the static library) chai, and where the executable links dynamically to my shared object, I get a double free error at the end of execution. This is most likely due to the static block that registers the chai plugin being called twice, which leads to chai being added twice to the list of the plugins. When exiting, the cleanup is done twice on the same object.
Here's a minimal working example.
The shared object's header:

$ cat testchai.hpp
#ifndef TESTCHAI_H
#define TESTCHAI_H
#include "chai/ArrayManager.hpp"
class TestChai
{
  public:
  void testChai();
};
#endif

and cpp file:

$ cat testchai.cpp
#include "testchai.hpp"
void TestChai::testChai()
{
  chai::ArrayManager *rm = chai::ArrayManager::getInstance();
}

and the main executable:

$ cat testchaimain.cpp
#include "chai/ArrayManager.hpp"
#include "testchai.hpp"
int main()
{
  chai::ArrayManager *rm = chai::ArrayManager::getInstance();
  TestChai t;
  t.testChai();
 return 0;
}

If now I compile the shared object:

$ g++ -o testchai.o -c testchai.cpp -I/path/to/chai/include -I/path/to/raja/include
$ g++ -shared -o testchai.so testchai.o /path/to/chai/lib/libchai.a /path/to/raja/libRAJA.a

and the executable:

$ g++ -o testchaimain.o -c testchaimain.cpp -I/path/to/chai/include -I/path/to/raja/include
$ g++ -o testchaimain testchaimain.o /path/to/chai/lib/libchai.a /path/to/chai/lib/libumpire.a /path/to/raja/libRAJA.a testchai.so

when I run I get a double free error:

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
$ ./testchaimain
free() double free detected in tchache 2
Aborted (core dumped)

Is this a proper issue or is it simply forbidden to have multiple objects compiled against the static chai library?

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

1 participant