fixed some leaks in the plugin system and its tests - related to #737