GNOME Bugzilla – Bug 97549
Gnome::Conf::Value::get_list_of_strings causes crashes
Last modified: 2011-01-16 23:35:19 UTC
There seems to be a memory ownership problem with the Gnome::Conf::Value::get_list_of_* family of methods. This program crashes during the destruction of the Gnome::Conf::Value : ------ CUT HERE ------ #include <gconfmm.h> #include <libgnomeuimm/init.h> #include <libgnomemm/main.h> int main(int argc, char**argv){ Gnome::Main kit("test","1.0",Gnome::UI::module_info_get(), argc, argv); Glib::RefPtr<Gnome::Conf::Client> client= Gnome::Conf::Client::get_default_client(); Glib::ustring key="/apps/test/testkey"; std::list<Glib::ustring> lst,lst2; lst.push_back("test-string-1"); lst.push_back("test-string-2"); client->set(key,lst); { Gnome::Conf::Value v(client->get(key)); lst2=v.get_list_of_strings(key); } return 0; } ------ CUT HERE ------ The compilation command is g++ `pkg-config --cflags --libs gconfmm-2.0 libgnomeuimm-2.0 libgnomemm-2.0` gconfmm_test.cc -o gconfmm_test -g -O0 and the backtrace:
+ Trace 29800
Is the example code above incorrect?
You have marked this as version gconfmm 1.2, but the Gnome::UI::module_info_get() stuff is clearly from gnomemm2. Do you mean gconfmm2? With gconfmm2, the code does not compile: test.cc: In function `int main (int, char **)': test.cc:19: no matching function for call to `Gnome::Conf::Value::get_list_of_strings (Glib::ustring &)' /gnome/gnome-2-0/INSTALL/include/gconfmm-2.0/gconfmm/value.h:97: candidates are: SArray Gnome::Conf::Value::get_list_of_strings () const If you give me some code that builds then I will investigate it.
Oops, yes.. Umm.... yes... The correct code follows. And it really is for 2.0. Sorry :-( Note that calling client->get_list_of_strings(key) works flawlessly. #include <gconfmm.h> #include <libgnomeuimm/init.h> #include <libgnomemm/main.h> int main(int argc, char**argv){ Gnome::Main kit("test","1.0",Gnome::UI::module_info_get(), argc, argv); Glib::RefPtr<Gnome::Conf::Client> client= Gnome::Conf::Client::get_default_client(); Glib::ustring key="/apps/test/testkey"; std::list<Glib::ustring> lst,lst2; lst.push_back("test-string-1"); lst.push_back("test-string-2"); client->set(key,lst); { Gnome::Conf::Value v(client->get(key)); lst2=v.get_list_of_strings(); } return 0; }
Created attachment 12070 [details] test.cc - simplified code
Confirmed. Here's a simplified version of the test code.
The attached patch should fix this issue; however, I'd like someone to comment on it, as I'm not quite certain of the ownership issues. The essence of it is that gconf_value_get_list returns static data belonging to the GConfValue, which is then promptly freed in the container_from_gslist_of_values_of_* functions in list_conversion.h
Created attachment 12114 [details] [review] patch for list_conversions.h
New, correct patch. Forgot an assignemt right in front of my eyes. On a side note: list_conversion.h should not be installed, as it deals only with internal conversions, that are not exposed to the user.
Created attachment 12179 [details] [review] new, all-improved patch for list_conversion.h
Yes, that seems sensible. I assume that gconf changed its memory management since GNOME 1.4, because I seem to have added that code for a reason. I added some const keywords to make it clearer that we shouldn't be freeing the lists or their items. Thanks a lot.