<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Hi Richard,</div><div class=""><br class=""></div><div class="">  I spoke with Paul since I know we ran into this some time ago and found a solution. Digging through</div><div class="">the github logs, here is where Paul implemented the solution we came up with:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; color: rgb(175, 173, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">commit 61500561a96d5cb8d471c18bdb38d911611f3da9</span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Author: Paul Mattione <<a href="mailto:pmatt@jlab.org" class="">pmatt@jlab.org</a>></span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Date:   Tue Mar 17 15:35:54 2015 +0000</span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    Make global static variables in DTranslationTable have function scope instead. Return these by reference from these container functions, and access only by these functions.</span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    This fixes the crash-at-end-of-program problem (double-free, corrupted-memory) mentioned in the rev 17681 hd_root commit. Remove abort() call from hd_root.</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">For example, at the top of <a href="http://dtranslationtable.cc" class="">DTranslationTable.cc</a> there is this:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Use one translation table for all threads</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">pthread_mutex_t& DTranslationTable::Get_TT_Mutex(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">       </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> pthread_mutex_t tt_mutex = PTHREAD_MUTEX_INITIALIZER;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">       </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> tt_mutex;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Previously, the “</span>tt_mutex” variable was global so when a plugin that had been linked with</div><div class="">the TTAB library was attached (dlopen), it automatically linked this. When the plugin is </div><div class="">detached (dlclose) it was treated it like it went out of scope, deleting it. Then, the same thing </div><div class="">happened at program exit leading to a double-free leading to a crash.</div><div class=""><br class=""></div><div class="">By replacing the global with a static local variable inside a globally accessible method, one</div><div class="">avoids this. So, you will need to hunt down where in the code a global variable is being used</div><div class="">and wrap it inside a global getter method as is done above in order to avoid these crashes.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">-David</div></span></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 13, 2016, at 3:11 PM, Paul Mattione <<a href="mailto:pmatt@jlab.org" class="">pmatt@jlab.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">It’s only #include’d in danarest.  So, this problem would apply to every single class that’s #include’d into a plugin (such as DChargedTrack), so it’s unavoidable.  <br class=""><br class=""> - Paul<br class=""><br class="">On Jul 13, 2016, at 3:05 PM, Richard Jones <<a href="mailto:richard.t.jones@uconn.edu" class="">richard.t.jones@uconn.edu</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">Hello Dave,<br class=""><br class="">I have run into a nasty problem with segfaults at program exit. This seems to be related to the appearance of duplicate instances of some classes (eg. DEventWriterREST) that are defined both in the plugin (danarest.so) and the static library that is linked into hd_root (libHDDM.a). What is your policy with regard to classes that are used both in the static library and in the base code? <br class=""><br class="">BTW there is the related question of why the DEventWriterREST is duplicated in two places in the tree, once in the Utilitiles/plugins/danarest and once in the libraries/HDDM area.<br class=""><br class="">-Richard Jones<br class="">_______________________________________________<br class="">Halld-offline mailing list<br class=""><a href="mailto:Halld-offline@jlab.org" class="">Halld-offline@jlab.org</a><br class="">https://mailman.jlab.org/mailman/listinfo/halld-offline<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></body></html>