After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 97549 - Gnome::Conf::Value::get_list_of_strings causes crashes
Gnome::Conf::Value::get_list_of_strings causes crashes
Status: RESOLVED FIXED
Product: gconfmm
Classification: Other
Component: general
git master
Other other
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2002-11-03 11:33 UTC by Tassos Bassoukos
Modified: 2011-01-16 23:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test.cc - simplified code (632 bytes, text/plain)
2002-11-05 19:53 UTC, Murray Cumming
  Details
patch for list_conversions.h (2.63 KB, patch)
2002-11-07 07:58 UTC, Tassos Bassoukos
none Details | Review
new, all-improved patch for list_conversion.h (2.74 KB, patch)
2002-11-08 22:31 UTC, Tassos Bassoukos
none Details | Review

Description Tassos Bassoukos 2002-11-03 11:33:44 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:

  • #0 mallopt
    from /lib/libc.so.6
  • #1 free
    from /lib/libc.so.6
  • #2 g_free
    from /usr/lib/libglib-2.0.so.0
  • #3 gconf_value_free
    from /usr/lib/libgconf-2.so.4
  • #4 gconf_value_copy
    from /usr/lib/libgconf-2.so.4
  • #5 gconf_value_free
    from /usr/lib/libgconf-2.so.4
  • #6 Gnome::Conf::Value::clear
    from /usr/lib/libgconfmm-1.3.so.7
  • #7 Gnome::Conf::Value::~Value
    from /usr/lib/libgconfmm-1.3.so.7
  • #8 main
    at gconfmm_test.cc line 20

Is the example code above incorrect?
Comment 1 Murray Cumming 2002-11-04 16:39:12 UTC
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.
Comment 2 Tassos Bassoukos 2002-11-05 00:28:02 UTC
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;
}
Comment 3 Murray Cumming 2002-11-05 19:53:41 UTC
Created attachment 12070 [details]
test.cc - simplified code
Comment 4 Murray Cumming 2002-11-05 19:54:10 UTC
Confirmed. Here's a simplified version of the test code.
Comment 5 Tassos Bassoukos 2002-11-07 07:44:49 UTC
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
Comment 6 Tassos Bassoukos 2002-11-07 07:58:47 UTC
Created attachment 12114 [details] [review]
patch for list_conversions.h
Comment 7 Tassos Bassoukos 2002-11-08 21:37:13 UTC
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.
Comment 8 Tassos Bassoukos 2002-11-08 22:31:59 UTC
Created attachment 12179 [details] [review]
new, all-improved patch for list_conversion.h
Comment 9 Murray Cumming 2002-11-09 13:05:44 UTC
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.