From 6054eeeae94690ba8a13aa73fc5b4548c1f38361 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 21 Aug 2014 17:23:42 +1000 Subject: [PATCH] Restructure free_command to afford protocol module more control This allows the protocol module first cleanup opportunity on Txn --- asyncqueue.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/asyncqueue.c b/asyncqueue.c index 5d262c62..6695a2b8 100644 --- a/asyncqueue.c +++ b/asyncqueue.c @@ -95,15 +95,24 @@ static const char *state_name(AsyncState the_state) */ static void free_command(pAQ_Cmd myCmd) { - free(myCmd->tran->out_buf); - free(myCmd->tran->inp_buf); - if (myCmd->tran->proto_private) - if (myCmd->tran->kill_private) - myCmd->tran->kill_private(myCmd->tran); - else - free(myCmd->tran->proto_private); - free(myCmd->tran); - free(myCmd); + if (myCmd) { + pAsyncTxn myTxn = myCmd->tran; + if (myTxn) { + /* + * Allow kill_private to clean it all if it wants + */ + if (myTxn->kill_private) + myTxn->kill_private(myTxn); + if (myTxn->out_buf) + free(myTxn->out_buf); + if (myTxn->inp_buf) + free(myTxn->inp_buf); + if (myTxn->proto_private) + free(myTxn->proto_private); + free(myTxn); + } + free(myCmd); + } } /* ---------------------------- Local ------------------------------------