Add call g_main_loop_unref function to remove GMainLoop object.
Move calling g_spawn_close_pid function.