Adds a check that fixes an invalid g_object_unref