Memfree 2

@mconst-nanosatisfi @jtrutna @jcappaert @bordicon @ebobby 

mconst's critical memfree fix has not yet been put into master, and so here it is.