memleak patch by (Gildas Bazin <gbazin at altern dot org>)