backport of memleak fix from trunk (-r1.62 -r1.63)
backport of memleak fix from trunk (-r1.62 -r1.63)

zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb,zyzyis/monetdb