Memory leak fix in the discover plugins method