loader: Guard against potential memory leaks