crash in __tcf_0
<p>In our application we observe a crash after its execution. The stack trace shows that the crash is because of the global variable present in the cpp file. The valgrind report generated shows the invalid free/read/write error, which means that it is trying to delete a memory which is no longer valid.</p>

<p><strong>File: crash.cpp</strong></p>

<pre><code>namespace abc
{
  MutexClass obj; //A is a class
  // remaining code

  ChildClass::ChildClass():Parent(obj){}

}
</code></pre>

<p>We then placed the given variable in an unnamed namespace, and we no longer get the crash and the valgrind does not report an invalid read/write/error:</p>

<p><strong>File: nocrash.cpp</strong></p>

<pre><code>namespace
{
  MutexClass obj;
}

namespace abc
{
  // remaining code
  ChildClass::ChildClass():Parent(obj){}
}
</code></pre>

<p>The above examples are a stripped down version of the class causing the problem.</p>

<p>We are not sure why placing the variable in unnamed namespace removes this problem. Does it change the clean-up order? We tried writing simple code but the clean-up order we observed were same for both the cases.</p>

<p><strong>The Mutex object is passed as parameter to base class constructor. The only purpose of the Mutex object is to used in the base class constructor. The Mutex object is not used anywhere else in the code.</strong></p>

<p>The valgrind report for the crash</p>

<p>=================================================</p>

<p>Thread 1:</p>

<p><strong>Invalid read of size 1</strong></p>

<p>at 0x3A24C08260: pthread_mutex_destroy (in /lib64/libpthread-2.5.so)</p>

<p>by 0x5ABE3DD: osl_destroyMutex (libuno_sal.so.3)</p>

<p>by 0xECD69D1: osl::Mutex::~Mutex() (mutex.hxx:65)</p>

<p>by 0xEF207F5: __tcf_0 (<strong>Dispose.cpp:27</strong>)</p>

<p>by 0x3A24033354: exit (in /lib64/libc-2.5.so)</p>

<p>by 0x3A2401D97A: (below main) (in /lib64/libc-2.5.so)</p>

<p>Address 0xeb6bb88 is 16 bytes inside a block of size 40 free'd</p>

<p>at 0x4A05B3E: free (vg_replace_malloc.c:323)</p>

<p>by 0x3A24033354: exit (in /lib64/libc-2.5.so)</p>

<p>by 0x3A2401D97A: (below main) (in /lib64/libc-2.5.so)</p>

<p><strong>Invalid write of size 4</strong></p>

<p>at 0x3A24C08272: pthread_mutex_destroy (in /lib64/libpthread-2.5.so)</p>

<p>by 0x5ABE3DD: osl_destroyMutex (in libuno_sal.so.3)</p>

<p>by 0xECD69D1: osl::Mutex::~Mutex() (mutex.hxx:65)</p>

<p>by 0xEF207F5: __tcf_0 (<strong>Dispose.cpp:27</strong>)</p>

<p>by 0x3A24033354: exit (in /lib64/libc-2.5.so)</p>

<p>by 0x3A2401D97A: (below main) (in /lib64/libc-2.5.so)</p>

<p>Address 0xeb6bb88 is 16 bytes inside a block of size 40 free'd</p>

<p>at 0x4A05B3E: free (vg_replace_malloc.c:323)</p>

<p>by 0x3A24033354: exit (in /lib64/libc-2.5.so)</p>

<p>by 0x3A2401D97A: (below main) (in /lib64/libc-2.5.so)</p>

<p><strong>Invalid free() / delete / delete[]</strong></p>

<p>at 0x4A05B3E: free (vg_replace_malloc.c:323)</p>

<p>by 0xECD69D1: osl::Mutex::~Mutex() (mutex.hxx:65)</p>

<p>by 0xEF207F5: __tcf_0 (<strong>Dispose.cpp:27</strong>)</p>

<p>by 0x3A24033354: exit (in /lib64/libc-2.5.so)</p>

<p>by 0x3A2401D97A: (below main) (in /lib64/libc-2.5.so)</p>

<p>Address 0xeb6bb78 is 0 bytes inside a block of size 40 free'd</p>

<p>at 0x4A05B3E: free (vg_replace_malloc.c:323)</p>

<p>by 0x3A24033354: exit (in /lib64/libc-2.5.so)</p>

<p>by 0x3A2401D97A: (below main) (in /lib64/libc-2.5.so)</p>

<p>=================================================</p>

<p>The Dispose.cpp :27 line has the mutex variable defined.</p>

<p>We would appreciate any help on this matter</p>

<p>Thanks,</p>

<p>Sudeep</p>
