Fix memory leaks

Authored by nienhueser on Jan 8 2017, 3:14 PM.