Fix double free + pointers reassign on shutdown