Re: Re: Convert zval array to char **

From: Date: Fri, 22 Jul 2005 22:52:25 +0000
Subject: Re: Re: Convert zval array to char **
References: 1 2 3 4 5  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2645@lists.php.net to get a copy of this message
> > Of course, it's also possible that the char* value returned by the > > function *is* malloc'd in which case I'd say you're missing a free(). > Actually there is a freeHash function. > I did not use it because I wanted to return the value. > > So I suppose the thing to do then would be to duplicate the returned > string to a new string in the php extension function and then free the > one returned by the lib function with their freeHash function. > Correct? > Right, the library will have used the malloc() syscall to allocate the string, but PHP wants any string value to be within Zend's Memory Management layer (otherwise you have "issues" when it comes time to dtor the value). So you'd replace RETURN_STRING(strHashValue, 1); with: RETVAL_STRING(strHashValue, 1); freeHash(strHashValue); Otherwise PHP will steadily leak strlen(strHashValue) + 1 bytes every time you call hsbc_cpi_make_hash(). -Sara

« previous php.pecl.dev (#2645) next »