Fix hang when MantidPlot shuts down on RHEL6

Refs #7819
Merge branch 'bugfix/7819_fix_memory_leaks' into develop