Fixed memory leak when unloading plugins