From 2ee7f4a6f8333528f6645d4bcfcc08f58879b2b9 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Mon, 7 Sep 2009 23:20:29 -0500 Subject: [PATCH] Fix g_at_chat_unref from command callback The resources were being used after being freed in this case --- gatchat/gatchat.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index e6fd5743..186c62ef 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -324,34 +324,36 @@ static void g_at_chat_finish_command(GAtChat *p, gboolean ok, char *final) { struct at_command *cmd = g_queue_pop_head(p->command_queue); + GSList *response_lines; /* Cannot happen, but lets be paranoid */ if (!cmd) return; - if (cmd->callback) { - GAtResult result; - - p->response_lines = g_slist_reverse(p->response_lines); - - result.final_or_pdu = final; - result.lines = p->response_lines; - - cmd->callback(ok, &result, cmd->user_data); - } - - g_slist_foreach(p->response_lines, (GFunc)g_free, NULL); - g_slist_free(p->response_lines); - p->response_lines = NULL; - - g_free(final); - - at_command_destroy(cmd); - p->cmd_bytes_written = 0; if (g_queue_peek_head(p->command_queue)) g_at_chat_wakeup_writer(p); + + response_lines = p->response_lines; + p->response_lines = NULL; + + if (cmd->callback) { + GAtResult result; + + response_lines = g_slist_reverse(response_lines); + + result.final_or_pdu = final; + result.lines = response_lines; + + cmd->callback(ok, &result, cmd->user_data); + } + + g_slist_foreach(response_lines, (GFunc)g_free, NULL); + g_slist_free(response_lines); + + g_free(final); + at_command_destroy(cmd); } struct terminator_info {