All this code is duplicated. These 2 leaks are also duplicated.