add free calls to avoid leaking memory in tests