comparison 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
comparison
equal deleted inserted replaced
1883:0fecaedb83fa 1884:71780cf68aa2
6571 tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); 6571 tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle));
6572 6572
6573 if(tree && GTK_IS_TREE_VIEW(tree) && 6573 if(tree && GTK_IS_TREE_VIEW(tree) &&
6574 (store = (GtkTreeModel *)gtk_object_get_data(GTK_OBJECT(tree), "_dw_tree_store"))) 6574 (store = (GtkTreeModel *)gtk_object_get_data(GTK_OBJECT(tree), "_dw_tree_store")))
6575 gtk_tree_model_get(store, (GtkTreeIter *)item, 0, &text, -1); 6575 gtk_tree_model_get(store, (GtkTreeIter *)item, 0, &text, -1);
6576 if(text)
6577 {
6578 char *temp = text;
6579 text = strdup(temp);
6580 g_free(temp);
6581 }
6576 #else 6582 #else
6577 text = (char *)gtk_object_get_data(GTK_OBJECT(item), "_dw_text"); 6583 text = (char *)gtk_object_get_data(GTK_OBJECT(item), "_dw_text");
6578 #endif 6584 #endif
6579 DW_MUTEX_UNLOCK; 6585 DW_MUTEX_UNLOCK;
6580 return text; 6586 return text;
7879 GtkWidget *clist; 7885 GtkWidget *clist;
7880 GList *list; 7886 GList *list;
7881 void *retval = NULL; 7887 void *retval = NULL;
7882 int _locked_by_me = FALSE; 7888 int _locked_by_me = FALSE;
7883 int type = _DW_DATA_TYPE_STRING; 7889 int type = _DW_DATA_TYPE_STRING;
7884 void **params; 7890 void **params = NULL;
7885 7891
7886 if(flags & DW_CR_RETDATA) 7892 if(flags & DW_CR_RETDATA)
7887 type = _DW_DATA_TYPE_POINTER; 7893 type = _DW_DATA_TYPE_POINTER;
7888 7894
7889 DW_MUTEX_LOCK; 7895 DW_MUTEX_LOCK;
7890 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); 7896 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle));
7891 7897
7892 if(!clist) 7898 if(!clist)
7893 { 7899 {
7894 DW_MUTEX_UNLOCK; 7900 DW_MUTEX_UNLOCK;
7895 return NULL; 7901 return retval;
7896 } 7902 }
7897 7903
7898 /* These should be separate but right now this will work */ 7904 /* These should be separate but right now this will work */
7899 if(flags & DW_CRA_SELECTED) 7905 if(flags & DW_CRA_SELECTED)
7900 { 7906 {
7902 7908
7903 if(list) 7909 if(list)
7904 { 7910 {
7905 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); 7911 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1));
7906 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); 7912 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data));
7907 retval = params ? params[type] : NULL;
7908 } 7913 }
7909 } 7914 }
7910 else if(flags & DW_CRA_CURSORED) 7915 else if(flags & DW_CRA_CURSORED)
7911 { 7916 {
7912 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GTK_CLIST(clist)->focus_row); 7917 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GTK_CLIST(clist)->focus_row);
7913 retval = params ? params[type] : NULL;
7914 } 7918 }
7915 else 7919 else
7916 { 7920 {
7917 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), 0); 7921 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), 0);
7918 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); 7922 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1));
7919 retval = params ? params[type] : NULL; 7923 }
7924 if(params)
7925 {
7926 if(type == _DW_DATA_TYPE_STRING && params[type])
7927 retval = strdup((char *)params[type]);
7928 else
7929 retval = (char *)params[type];
7920 } 7930 }
7921 DW_MUTEX_UNLOCK; 7931 DW_MUTEX_UNLOCK;
7922 return retval; 7932 return retval;
7923 } 7933 }
7924 7934
7935 GtkWidget *clist; 7945 GtkWidget *clist;
7936 GList *list; 7946 GList *list;
7937 void *retval = NULL; 7947 void *retval = NULL;
7938 int _locked_by_me = FALSE; 7948 int _locked_by_me = FALSE;
7939 int type = _DW_DATA_TYPE_STRING; 7949 int type = _DW_DATA_TYPE_STRING;
7940 void **params; 7950 void **params = NULL;
7941 7951
7942 if(flags & DW_CR_RETDATA) 7952 if(flags & DW_CR_RETDATA)
7943 type = _DW_DATA_TYPE_POINTER; 7953 type = _DW_DATA_TYPE_POINTER;
7944 7954
7945 DW_MUTEX_LOCK; 7955 DW_MUTEX_LOCK;
7946 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); 7956 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle));
7947 7957
7948 if(!clist) 7958 if(!clist)
7949 { 7959 {
7950 DW_MUTEX_UNLOCK; 7960 DW_MUTEX_UNLOCK;
7951 return NULL; 7961 return retval;
7952 } 7962 }
7953 7963
7954 /* These should be separate but right now this will work */ 7964 /* These should be separate but right now this will work */
7955 if(flags & DW_CRA_SELECTED) 7965 if(flags & DW_CRA_SELECTED)
7956 { 7966 {
7966 list = list->next; 7976 list = list->next;
7967 counter++; 7977 counter++;
7968 } 7978 }
7969 7979
7970 if(list) 7980 if(list)
7971 {
7972 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); 7981 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data));
7973 retval = params ? params[type] : NULL;
7974 }
7975 } 7982 }
7976 } 7983 }
7977 else if(flags & DW_CRA_CURSORED) 7984 else if(flags & DW_CRA_CURSORED)
7978 { 7985 {
7979 /* There will only be one item cursored, 7986 /* There will only be one item cursored,
7985 { 7992 {
7986 int pos = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_querypos")); 7993 int pos = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_querypos"));
7987 7994
7988 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), pos); 7995 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), pos);
7989 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(pos+1)); 7996 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(pos+1));
7990 retval = params ? params[type] : NULL; 7997 }
7998 if(params)
7999 {
8000 if(type == _DW_DATA_TYPE_STRING && params[type])
8001 retval = strdup((char *)params[type]);
8002 else
8003 retval = (char *)params[type];
7991 } 8004 }
7992 DW_MUTEX_UNLOCK; 8005 DW_MUTEX_UNLOCK;
7993 return retval; 8006 return retval;
7994 } 8007 }
7995 8008