GTK troubles...again...

This is a discussion on GTK troubles...again... within the Linux Programming forums, part of the Platform Specific Boards category; Hello, this is my second post today, and its the second question. I've got a programm, which creates a seg ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    17

    GTK troubles...again...

    Hello,
    this is my second post today, and its the second question.

    I've got a programm, which creates a seg fault after some days. I dont know, where this fault is generated.
    Now i tried to analyse the programm. Therefore i used purify. And now the problem beginns.
    With purify i get thousands and thousands of "Uninitialized memory read" errors.
    But those errors seem to be in the gtk library.
    I will post here a function which creates such errors, maybe somebody had the same problem and knows, how to solve it.

    Code:
    static GtkWidget *get_search_area () {
    	GtkWidget *input_field;
    	GtkWidget *search_button;
    	GtkWidget *hboxSearch;
    	GList *glist = NULL;
    	
    	// input field
    	input_field = gtk_entry_new_with_max_length(5);
    	gtk_entry_set_width_chars(GTK_ENTRY(input_field), 5);
    
    	//combobox
    	combo_box = gtk_combo_new();
    	
    	glist = g_list_append (glist, "All");
        	glist = g_list_append (glist, "K15-U");
    
    	search_button = gtk_button_new_with_label ("Update Users");
    	g_signal_connect (G_OBJECT (search_button), "clicked",
    	G_CALLBACK (update_button), input_field);
    	gtk_widget_set_size_request (GTK_WIDGET (search_button), 80, 20);
    	
    	gtk_widget_show (input_field);
    	gtk_widget_show (combo_box);
    	gtk_widget_show (search_button);
    
    	hboxSearch = gtk_hbox_new (FALSE, 20);
    	gtk_box_pack_start (GTK_BOX (hboxSearch), input_field, FALSE, TRUE, 5); //This line is reported by purify
    	gtk_box_pack_start (GTK_BOX (hboxSearch), combo_box, FALSE, TRUE, 5);
    	gtk_box_pack_start (GTK_BOX (hboxSearch), search_button, FALSE, TRUE, 0);
    	
    	gtk_widget_show(hboxSearch);
    
    	return hboxSearch;
    }
    Here is the purify output of this function:

    Code:
          This is occurring while in:
                gtk_hbox_size_allocate [libgtk-x11-2.0.so.0]
                g_closure_invoke [libgobject-2.0.so.0]
                signal_emit_unlocked_R [libgobject-2.0.so.0]
                g_signal_emit_valist [libgobject-2.0.so.0]
                gtk_signal_emit [libgtk-x11-2.0.so.0]
                gtk_widget_size_allocate [libgtk-x11-2.0.so.0]
          Reading 4 bytes from 0x11ec84 in the heap (1 byte at 0x11ec87 uninit).
          Address 0x11ec84 is 4 bytes into a malloc'd block at 0x11ec80 of 8 bytes.
          This block was allocated from:
                malloc         [rtlib.o]
                g_malloc       [libglib-2.0.so.0]
                gtk_box_pack_start [libgtk-x11-2.0.so.0]
                get_search_area [MainWindow.c:256]
                           gtk_widget_show (search_button);
                           // hbox to put the search button and input field in
                           hboxSearch = gtk_hbox_new (FALSE, 20);
                =>         gtk_box_pack_start (GTK_BOX (hboxSearch), input_field, FALSE, TRUE, 5);
                           gtk_box_pack_start (GTK_BOX (hboxSearch), combo_box, FALSE, TRUE, 5);
                           gtk_box_pack_start (GTK_BOX (hboxSearch), search_button, FALSE, TRUE, 0);
    I hope anybody knows this behaviour of gtk or my code, because i haven't got a clue.
    Thank you

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    First thing to do with a new tool like that is start with your "hello world" equivalent GTK program and observe its behaviour on something which is "obviously" correct.

    > With purify i get thousands and thousands of "Uninitialized memory read" errors.
    > But those errors seem to be in the gtk library.
    If you pass a pointer to uninitialised memory to GTK, then it might appear that the library is reading uninitialised memory.

    Does your malloc have an option to fill allocated memory with a pattern (rather than either zeros or whatever was there from last time). Ditto for free, fill deallocated memory with a pattern to trap sneaky use after free problems.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    Valgrind didn't found anything wrong with that code, but from your other post I assume that you're compiling it on Solaris.
    You _coud_ try not to use deprecated widgets and functions... Migrating from GtkCombo to GtkComboBoxEntry and gtk_entry_new_with_max_length() (read the "Note").

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    25
    I have not read the entire code closely--I will do so later--but I notice that you are using deprecated functions. For example, gtk_entry_new_with_max_length() is a deprecated function and should not be used in newly written code.

    Another function that might be a source of problems is gtk_combo_new(). My GTK+ documentation does not even list it. I have only ever used gtk_combo_box_new_text() and I have never experienced a problem, so if the entries are only going to be text entries, you might want to look into this latter function instead.

    Like I said, I have not read the code very closely. I will come back to it later.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    17
    Ok, you're right, those functions are deprecated. But GtkComboBoxEntry for example exists since GTK 2.4. The problem now is, that i have to use GTK 2.0. This is the actual stable Solaris version, as far as i know. If somebody can correct me here, please do so.

    I also testet a simple helloWorld program, same behaviour. Only by creating the window, there are several Memory Errors.
    By resizing the window, many more errors are created.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW32 and gtk setup in Windows
    By Joelito in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-05-2009, 11:39 AM
  2. Replies: 1
    Last Post: 09-22-2008, 05:49 AM
  3. Help on GTK
    By kakashi in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2006, 02:33 AM
  4. GTK Help
    By Cronkilla in forum C Programming
    Replies: 2
    Last Post: 08-24-2004, 07:23 PM
  5. QT or GTK
    By mart_man00 in forum Linux Programming
    Replies: 4
    Last Post: 03-24-2003, 10:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21