Re: How many times can I call gtk_label_set_markup()?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Igor,

On Fri, 8 Apr 2011 13:33:29 -0700 you wrote:
> >> gtk_label_set_markup( GTK_LABEL( data1 ), m_data1->str );
> >
> >> g_free( m_data1->str );
> >
> > ^^^^^^^^^^^^^^^^^^^^^^^^
> > Really? What is m_data1? Your earlier extract suggests you reuse it after
> > this.
> 
> By doing g_free() I'm giving anownership of the markup string to the control.
> Or I don't need this?

No, by doing g_free you are releasing the memory allocated by
m_data1->str. While this is probably OK because gtk_label_set_markup
takes a copy, it is most definitely not "giving ownership". The example
in the Gtk docs does it because the markup string is dynamically
created and immediately disposed of, because it's being escaped. In
your case it's pointed to by a structure member, which strongly hints
at it not being such a temporary object. In any case, it's very bad
practice leaving a hanging pointer to memory you've just free'd, so
common advice is to set m_data1->str to NULL immediately after the
g_free call. If that looks like the wrong thing in your program, then
the g_free call is wrong.

Cheers,
Rob
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux