Andrei,
Looking into GtkCList and GtkCTree constructors, both of which need
overrides to avoid the '_with_titles' variant and to get some i18n support.
The first bit of code below comes directly from the php-gtk1 overrides and
suffers from memory leaks:
target_hash = HASH_OF(php_titles);
titles = emalloc(sizeof(gchar *) * columns);
zend_hash_internal_pointer_reset(target_hash);
while (zend_hash_get_current_data(target_hash, (void **)&temp_title)
== SUCCESS) {
convert_to_string_ex(temp_title);
titles[i++] = estrndup(Z_STRVAL_PP(temp_title),
Z_STRLEN_PP(temp_title)); /* this leaks 1 byte per title char (+ 1) */
zend_hash_move_forward(target_hash);
}
The second bit of code is a much-reduced version of what I currently have:
titles = emalloc(sizeof(gchar *) * columns);
zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_titles));
while (zend_hash_get_current_data(Z_ARRVAL_P(php_titles), (void
**)&temp_title) == SUCCESS) {
convert_to_string_ex(temp_title);
titles[i++] = Z_STRVAL_PP(temp_title); /* this doesn't leak at
all, but it doesn't feel too safe either... */
zend_hash_move_forward(Z_ARRVAL_P(php_titles));
}
Is it better to live with the leaks in this situation? Either way works,
for practical purposes... or is there a third way I didn't fall across yet?
- Steph
(ISP's been broken all day following stormy weather here - sorry, you'll be
getting everything at once from me :-\)
--
PHP-GTK Development Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
|