delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2012/07/08/13:50:35

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Date: Sun, 8 Jul 2012 10:44:10 -0700
From: Andrew Poelstra <asp11 AT sfu DOT ca>
To: geda-user AT delorie DOT com
Subject: Re: [geda-user] [PATCH] gtk hid file chooser problems
Message-ID: <20120708174410.GG1637@malakian.lan>
References: <4FF8B79E DOT 6000503 AT cox DOT net>
<20120708041830 DOT GD1637 AT malakian DOT lan>
<4FF9B5D9 DOT 5050809 AT cox DOT net>
<20473 DOT 45333 DOT 154735 DOT 732374 AT vagabond DOT local>
<4FF9C470 DOT 9030204 AT cox DOT net>
MIME-Version: 1.0
In-Reply-To: <4FF9C470.9030204@cox.net>
User-Agent: Mutt/1.5.20 (2009-12-10)
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sun, Jul 08, 2012 at 10:33:36AM -0700, Eric Brombaugh wrote:
> On 07/08/2012 09:11 AM, Patrick Bernaud wrote:
> >Hi,
> >
> >Eric Brombaugh writes:
> >  > [...]
> >  > +  {
> >  > +	gchar *default_path;
> >  > +	gchar *uri;
> >  > +	default_path = g_file_new_for_path (g_get_current_dir());
> >  > +	uri = g_file_get_uri (default_path);
> >  > +	gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
> >  > +	g_free (uri);
> >  > +  }
> >
> >A couple of things:
> >
> >- g_file_new_for_path() returns a GFile*, not a gchar*.
> >
> >- the string returned by g_get_current_dir() has to be freed and
> >   'default_path' possibly unref-ed.
> 
> Thanks for the suggestions - I'll look into cleaning this up and resubmit.
> 
> I did try to g_free(default_path) while testing this but it always
> resulted in a core dump.
>

Yep -- default_path needs to be a GFile *, and you "free" it by calling
g_object_unref() on it, like so:

  GFile *default_path; 
  default_path = g_file_new_for_path (g_get_current_dir());
  ...
  g_object_unref (G_OBJECT (default_path));

This tells the Gtk+ garbage collector that nobody is using default_path
anymore, and it's free to delete it.

-- 
Andrew Poelstra
Email: asp11 at sfu.ca OR apoelstra at wpsoftware.net
Web:   http://www.wpsoftware.net/andrew
"You shouldn't trust every quote you read on the Internet." -- Socrates

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019