Mercurial > dwindows
diff gtk/dw.c @ 1884:71780cf68aa2
More container and tree changes on all platforms regarding memory.
This should fix GTK3 memory leaks I wasn't previously aware of...
but it will cause all platforms to leak memory if strings returned
from dw_container_query_start(), dw_container_query_next() and
dw_tree_get_title() are not freed with dw_free() when using version 3.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 28 Aug 2013 23:47:40 +0000 |
parents | 60abfe87dc05 |
children | f7d408a47752 |
line wrap: on
line diff
--- a/gtk/dw.c Thu Aug 15 18:51:56 2013 +0000 +++ b/gtk/dw.c Wed Aug 28 23:47:40 2013 +0000 @@ -6573,6 +6573,12 @@ if(tree && GTK_IS_TREE_VIEW(tree) && (store = (GtkTreeModel *)gtk_object_get_data(GTK_OBJECT(tree), "_dw_tree_store"))) gtk_tree_model_get(store, (GtkTreeIter *)item, 0, &text, -1); + if(text) + { + char *temp = text; + text = strdup(temp); + g_free(temp); + } #else text = (char *)gtk_object_get_data(GTK_OBJECT(item), "_dw_text"); #endif @@ -7881,7 +7887,7 @@ void *retval = NULL; int _locked_by_me = FALSE; int type = _DW_DATA_TYPE_STRING; - void **params; + void **params = NULL; if(flags & DW_CR_RETDATA) type = _DW_DATA_TYPE_POINTER; @@ -7892,7 +7898,7 @@ if(!clist) { DW_MUTEX_UNLOCK; - return NULL; + return retval; } /* These should be separate but right now this will work */ @@ -7904,19 +7910,23 @@ { gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); - retval = params ? params[type] : NULL; } } else if(flags & DW_CRA_CURSORED) { params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GTK_CLIST(clist)->focus_row); - retval = params ? params[type] : NULL; } else { params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), 0); gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); - retval = params ? params[type] : NULL; + } + if(params) + { + if(type == _DW_DATA_TYPE_STRING && params[type]) + retval = strdup((char *)params[type]); + else + retval = (char *)params[type]; } DW_MUTEX_UNLOCK; return retval; @@ -7937,7 +7947,7 @@ void *retval = NULL; int _locked_by_me = FALSE; int type = _DW_DATA_TYPE_STRING; - void **params; + void **params = NULL; if(flags & DW_CR_RETDATA) type = _DW_DATA_TYPE_POINTER; @@ -7948,7 +7958,7 @@ if(!clist) { DW_MUTEX_UNLOCK; - return NULL; + return retval; } /* These should be separate but right now this will work */ @@ -7968,10 +7978,7 @@ } if(list) - { params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); - retval = params ? params[type] : NULL; - } } } else if(flags & DW_CRA_CURSORED) @@ -7987,7 +7994,13 @@ params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), pos); gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(pos+1)); - retval = params ? params[type] : NULL; + } + if(params) + { + if(type == _DW_DATA_TYPE_STRING && params[type]) + retval = strdup((char *)params[type]); + else + retval = (char *)params[type]; } DW_MUTEX_UNLOCK; return retval;