Backport memory fix (2014-03-22T03:04:53Z!dancol@dancol.org) from trunk