Re: GtkCList, GtkCTree and memleaks
| From: | Andrei Zmievski | Date: | Fri, 10 Feb 2006 03:42:34 +0000 |
| Subject: | Re: GtkCList, GtkCTree and memleaks | ||
| References: | 1 | Groups: | php.gtk.dev |
| Request: | Send a blank email to php-gtk-dev+get-2391@lists.php.net to get a copy of this message | ||
Did you ever commit this?
-Andrei
On Dec 18, 2005, at 12:34 PM, Steph Fox wrote:
OK, I took advice on this now (thanks Tony) and the memleaks are finally dead. Need to test clist, will commit tomorrow (I don't think there's anything contentious here - it's more or less the same behaviour we had before). - Steph (gorn) ----- Original Message ----- From: "Steph Fox" <steph@zend.com> To: "Andrei" <andrei@gravitonic.com> Cc: "PHP-GTK dev" <php-gtk-dev@lists.php.net> Sent: Saturday, December 17, 2005 10:05 PM Subject: [PHP-GTK-DEV] GtkCList, GtkCTree and memleaksAndrei, 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:--PHP-GTK Development Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phptarget_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 atall, 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