Fix memory allocation and deallocation.

Signed-off-by: Thiago Farina <tfarina@chromium.org>