Re: glib 2.34 g_main_context_unref hangs



On 01/17/2013 02:48 PM, Ken Bass wrote:
> On 01/17/2013 01:58 PM, Dan Winship wrote:
>> g_main_context_default() does not give you a ref on the default context,
>> so your code here is destroying an object internal to glib. If you call
>> this more than once (or, if you do *anything* involving the default
>> context after this point), I'd definitely expect it to fail.
>>
>> Beyond that, it's hard to say what you might be doing wrong without
>> seeing more code.
>>
>>
> Odd that it worked all these years

Yeah, probably you were just lucky before...

> For some reason I was under the impression it gave me a reference,
> particularly because
> when I look at that default context, its ref_count is 1, not 0.

Right, it's created with a ref_count of 1 when you first call
g_main_context_default(), but every time you call it after that, it just
returns the same one again without reffing it.

> My clean
> up routine is the last thing executed before exit(), so
> wouldn't this mean there is a memory leak?

If you are only calling the cleanup routine once, then there shouldn't
be any problem... is it possible you're freeing the GMainContext twice
somehow?

Anyway, there is no memory "leak" (because glib still has a pointer to
the context, and could still return it it to you if you called
g_main_context_default() again). There is just memory that is left
unfreed on exit, which is not a bug. (OTOH, if you are valgrinding and
trying to get rid of all possible leaks, it is useful to be able to free
some of that stuff, and I know that freeing the default GMainContext
immediately before exit *does* work, because all of the libsoup test
programs do that. So, there may be something else going wrong in your
code, like trying to free it twice or something.)

-- Dan



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