Re: Correct way to deallocate an unix signal source



On Mon, 2019-03-18 at 14:38 +0100, Enrico Mioso wrote:
Regarding the code, at exit I do the following:
if (my_state->mainloop) {
      g_main_loop_unref(my_state->mainloop);
      my_state->mainloop = NULL;
}

if (my_state->ctx) {
      g_main_context_unref(my_state->ctx);
      my_state->ctx = NULL;
}

That looks fine. If you depend on GLib ≥ 2.34, you can instead do:

g_clear_pointer (&my_state->mainloop, g_main_loop_unref);
g_clear_pointer (&my_state->ctx, g_main_context_unref);

which is equivalent, but simplifies things a bit.

Philip


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