Fix potential double free after linking modules