Ok, according to my OReilly "Programming PHP" book by Rasmus Lerdorf, the emalloc and efree functions work exactly the same as malloc and free. It says:

-----

if you emalloc() something and forget to efree() it, PHP prints a leak warning like this if you are running in debug mode (enabled by compiling PHP with the --enable-debug switch):

foo.c(123) : Freeing 0x0821E5FC (20 bytes), script=foo.php
Last leak reported 1 time

-----

so the docs do not agree... Im more apt to believe the book I have, since it goes on like this for a few pages about tracking down memory leaks... plus Rasmus wrote it ;)

The reason why in your code there is no 'efree' is because of the '0' flag passed to 'RETURN_STRINGL'. If that was a '1', they would have to efree it.

--

Brian 'Bex' Huff
[EMAIL PROTECTED]
Phone: 952-903-2023
Fax: 952-829-5424



Mikey wrote:

Im pretty sure you still need to 'efree' what you 'emalloc'.  Every time
I forgot to 'efree' something, I would get a bunch of error messages
about memory leaks.  The errors were nice and verbose, tho... as long as
I was running the debug version of the dlls.

Which is what I would have assumed, but for what I read in the manual.


So either the documentation is wrong, and you have to efree
everything... or else the error messages about memory leaks that I keep
getting can be ignored...

I'd be curious to know the answer as well...

Well, I decided to see how the big boys dealt with strings, and had a root
around ext/standard.  The following function is from string.c:

PHP_FUNCTION(bin2hex)
{
	zval **data;
	char *result;
	size_t newlen;

	if (ZEND_NUM_ARGS() != 1 ||
        zend_get_parameters_ex(1, &data) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	convert_to_string_ex(data);

	result = php_bin2hex(Z_STRVAL_PP(data), Z_STRLEN_PP(data), &newlen);

	if (!result) {
		RETURN_FALSE;
	}

	RETURN_STRINGL(result, newlen, 0);
}

As you can see, result is emalloc()'d, but not efree()'d at the end - looks
like the docs are right.  I have since tried using this approach in a test
function and do not get any errors when I compile - what do you use for your
build?

regards,

Mikey





**All Electronic Mail sent from the Stellent, Inc Electronic Communication Network is scanned by Antigen 7.0.**

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to