Re: emitting the "delete_event" in a "key_press_event" --> crash



Olivier Sessink wrote:

g_signal_handlers_destroy(G_OBJECT(testwin->win));
gtk_widget_destroy(testwin->win);    g_free(testwin);

Here's one more bug - you may call gfree two times.

why is this a bug then? what is the problem with this code?

You had one handler for "delete_event" and "destroy". Tracing:

1. You allocates a piece of memory: testwin = g_new(...);
2. Then you pass testwin as a parameter to "delete_event" and "destroy" callbacks
(wich are the same function).
3. "delete_event" signalled - callback called first time.
4. You call gtk_widget_destroy() inside callback, GtkObjects code will emit "destroy"
some ns later.
5. "destroy" signalled - callback called second time.
6. You call gtk_widget_destroy() inside callback, no "destroy" will be emitted this time,
because GtkObject knows that dispose process is running.
7. You call gfree() - testwin freed.
8. Getting out from second callback's call.
9. You call gfree() on already freed on stage 7) testwin - this is a bug.
10. One more bug - you are not returning value from "delete_event" callback. But this
is not much important here, because you've called gtk_widget_destroy().

Olexiy





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