From 99dea317f0ee31125ff182725e30df4e717fa7da Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 21 Aug 2014 09:42:19 +1000 Subject: [PATCH] Refactor free of command/transaction code to function --- asyncqueue.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/asyncqueue.c b/asyncqueue.c index e1c52173..5d262c62 100644 --- a/asyncqueue.c +++ b/asyncqueue.c @@ -90,6 +90,22 @@ static const char *state_name(AsyncState the_state) return ""; } +/* + * Free the command and transaction structures and their contents + */ +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); +} + /* ---------------------------- Local ------------------------------------ CreateSocketAdress stolen from Tcl. Thanks to John Ousterhout */ @@ -165,15 +181,7 @@ static void AQ_Purge(pAsyncQueue self) self->command_head = myCmd->next; } else self->command_head = self->command_tail = NULL; - 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); + free_command(myCmd); myCmd = self->command_head; } } @@ -458,15 +466,7 @@ static int PopCommand(pAsyncQueue self) StartCommand(self); } else self->command_head = self->command_tail = NULL; - 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); + free_command(myCmd); return 1; }