Plug leaks on error paths.

Found with 'make test' on a --enable-debug php build (which does leak checking).

Change-Id: If231d7a1ee126fad8e4f9ca818b243750c32cf2b
Merge "Plug leaks on error paths."