Fixed pthread possible leakages