g_free segfaults, gtk-bookmarks, etc...
- From: Brian Thomason <brian thomason linspireinc com>
- To: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: g_free segfaults, gtk-bookmarks, etc...
- Date: Wed, 25 May 2005 14:22:47 -0700
Hi,
I have attached some code that I have added to the
"gtk_file_chooser_widget_set_start_dir" function in
gtkfilechooserwidget.c in gtk+ 2.4.13. It compiles and functions
perfectly fine, but I'm sure I'm introducing some memory leaks here that
I'd like to get worked out.
Here are the local variables I create:
gchar *home_dir;
gchar *test;
gchar *contents;
gchar *bookmark;
char **gtk_bookmarks;
gchar *bookmark_file;
GError *error;
Attempting to do a g_free() on any of these causes gtk+ to segfault.
I'm pretty ignorant when it comes to C (as you can probably tell just by
looking at these few lines of code attached) and even more ignorant of
glib, so any help here would be greatly appreciated.
On a related side note, we added this chunk of code to:
1.) Check to see if the user is located in ~
2.) If the user is in ~, default to the user's first gtk-bookmark as the
start directory
3.) If that bookmark contains the env variable $HOME, expand it with
g_get_home_dir ()
We do this because we like for 90% of our apps to default to the user's
Documents folder, which for us is ~/My Documents. Therefore, in our
gtk+ package, we have a postinst script which installs a copy of
~/.gtk-bookmarks in each user's home directory. We also install a copy
of it in /etc/skel so that each new user created will have a copy of it.
Unfortunately, the adduser script (which we plan on modifying in the
near future) does not expand environment variables in files it copies
from /etc/skel to ~.
Getting to the point, I'd like to request that gtk+ respected
environment variables (Well, at least $HOME) in gtk-bookmarks. I
attempted hacking support in, but it failed (big surprise with my C
skills ;-) ) and even tried hacking in support for creating a
.gtk-bookmarks file on the fly for each user who doesn't have one, which
would solve my issues as well, but I ended up just getting segfaults.
(Again, big surprise) Not to mention, these two hacks are exactly that
anyway, hacks, and it would be great if gtk+ simply natively supported
env variables in gtk-bookmarks.
Thanks in advance for your time, and I hope to hear some feedback from
you soon.
Until next time,
Brian
gchar *
gtk_file_chooser_widget_set_start_dir (gchar *current_folder)
{
gchar *home_dir;
gchar *test;
gchar *contents;
gchar *bookmark;
char **gtk_bookmarks;
gchar *bookmark_file;
GError *error;
home_dir = g_get_home_dir ();
bookmark_file = g_strconcat (home_dir,"/.gtk-bookmarks",NULL);
if (!strcmp(home_dir,current_folder))
{
if (g_file_test(bookmark_file, G_FILE_TEST_IS_REGULAR))
{
if (g_file_get_contents(bookmark_file,&contents,NULL,&error))
{
gtk_bookmarks = g_strsplit(contents,"\n",-1);
bookmark = g_filename_from_uri(gtk_bookmarks[0],NULL,&error);
test = g_strrstr(bookmark,"$HOME");
if (test)
{
bookmark = g_strjoinv(home_dir, g_strsplit(bookmark, "$HOME", -1));
}
current_folder = bookmark;
}
}
return current_folder;
}
else
{
return current_folder;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]