Fix #231 memory leak