llnl / llnl/CHAI

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

Open
#216 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
111
Forks
23
Avg merge
2d 7h
Merged PRs (30d)
4

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported failure with testchai.hpp, testchai.cpp, and testchaimain.cpp using the supplied static-library and shared-object build commands. Inspect ArrayManager.hpp and the static plugin-registration path described in the report; done means the executable using CHAI in both objects exits without a double-free.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.