PCBC-213: Mixing malloc and efree is not a good thing

some of these functions used a mix of PHP's internal
memory allocation functions and libc.. that's not a good ting
to do ;)

Change-Id: I5c7096146ce3eb65a4803d82e5758e90f28950a1
Reviewed-on: http://review.couchbase.org/25306
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>