Refactor free of command/transaction code to function

This commit is contained in:
Douglas Clowes
2014-08-21 09:42:19 +10:00
parent f1f9ee2c01
commit 99dea317f0

View File

@ -90,6 +90,22 @@ static const char *state_name(AsyncState the_state)
return "<unknown>";
}
/*
* 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;
}