diff --git a/asyncprotocol.c b/asyncprotocol.c index fc243d1a..cdfeae05 100644 --- a/asyncprotocol.c +++ b/asyncprotocol.c @@ -286,7 +286,6 @@ int AsyncProtocolAction(SConnection * pCon, SicsInterp * pSics, void defaultKillPrivate(pAsyncProtocol p) { if (p->privateData) { - /* TODO: should we do anything? */ free(p->privateData); } } @@ -295,15 +294,22 @@ void AsyncProtocolKill(void *pData) { pAsyncProtocol self = (pAsyncProtocol) pData; int i; - if (self->pDes) - DeleteDescriptor(self->pDes); - if (self->sendTerminator != NULL) - free(self->sendTerminator); - for (i = 0; i < 10; ++i) - if (self->replyTerminator[i] != NULL) - free(self->replyTerminator[i]); if (self->killPrivate) self->killPrivate(self); + if (self->pDes) + DeleteDescriptor(self->pDes); + self->pDes = NULL; + if (self->protocolName) + free(self->protocolName); + self->protocolName = NULL; + if (self->sendTerminator != NULL) + free(self->sendTerminator); + self->sendTerminator = NULL; + for (i = 0; i < 10; ++i) { + if (self->replyTerminator[i] != NULL) + free(self->replyTerminator[i]); + self->replyTerminator[i] = NULL; + } } pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics, @@ -338,6 +344,7 @@ pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics, AsyncProtocolKill(self); return NULL; } + self->protocolName = strdup(protocolName); self->sendCommand = defaultSendCommand; self->handleInput = defaultHandleInput; self->handleEvent = defaultHandleEvent; diff --git a/asyncprotocol.h b/asyncprotocol.h index 259e12cc..5e79e968 100644 --- a/asyncprotocol.h +++ b/asyncprotocol.h @@ -45,7 +45,7 @@ struct __async_txn { int inp_idx; /**< index of next character (number already received) */ AsyncTxnHandler handleResponse; /**< Txn response handler of command sender */ void *proto_private; /**< Protocol Private structure */ - void (*kill_private) (struct __async_txn *pTxn); /**< if it needs killing */ + void (*kill_private) (pAsyncTxn pTxn); /**< if it needs killing */ void *cntx; /**< opaque context used by command sender */ /* The cntx field may be used by protocol handler from sendCommand * as long as it is restored when response is complete