Re: checking status of GString
- From: Owen Taylor <otaylor redhat com>
- To: Aaron Walker <amwalker gate net>
- Cc: gtk-list redhat com
- Subject: Re: checking status of GString
- Date: 30 Nov 1999 09:45:08 -0500
Aaron Walker <amwalker@gate.net> writes:
> I have a callback that is called when I exit the main window:
>
> void main_destroy_cb (GtkWidget *widget, GWindow *gfind)
> {
> g_string_free(gfind->cmd, TRUE);
> g_free(gfind->entry);
> g_free(gfind);
> gtk_main_quit();
> }
>
> The GString gfind->cmd is initialize in the function that calls this
> callback, which means that on exit, my program is assuming that
> gfind->cmd has been initialized. I thought that this would work to
> check it:
>
> if(gfind->cmd != NULL)
> g_string_free(gfind->cmd, TRUE);
>
> which didn't work, so I tried:
>
> if(gfind->cmd->str != NULL)
> g_string_free(gfind->cmd, TRUE);
>
> which also did not work (segfaults).
>
> I am trying to avoid initializing the GString right away, to prevent
> this. I would just like to check if it is null or not.
Well, you need to remember that if you create a structure
with malloc() or g_new(), the fields of the structure will
not be initialized to NULL. You need to do this explicitely
yourself. Alternatively, you can use the functions
g_malloc0() and g_new0() to zero out the memory when it
is allocated.
[ Actually, assumming that NULL will have a bit-pattern of
all zeros is not standard ANSI C, though it works
universally on the platforms where GTK+ runs. ]
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]