memory: Fix memory leak.

This fix is based on
https://github.com/tornadoweb/tornado/commit/769bc52e11656788782a6e7a922ef646503f9ab0

Change-Id: I22ca6ad29cfbf642c85a8ff0393dee94c818930b
3 files changed