Fix a memory leak when media library is disabled