@@ -76,8 +76,10 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
/* construct a new message */
pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
- if (!pstrMessage)
- return -ENOMEM;
+ if (!pstrMessage) {
+ result = -ENOMEM;
+ goto ERRORHANDLER;
+ }
pstrMessage->u32Length = u32SendBufferSize;
pstrMessage->pstrNext = NULL;
pstrMessage->pvBuffer = kmalloc(u32SendBufferSize, GFP_ATOMIC);
@@ -104,10 +106,12 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
up(&pHandle->hSem);
ERRORHANDLER:
- /* error occured, free any allocations */
- if (pstrMessage) {
- kfree(pstrMessage->pvBuffer);
- kfree(pstrMessage);
+ if (result) {
+ /* error occured, free any allocations */
+ if (pstrMessage) {
+ kfree(pstrMessage->pvBuffer);
+ kfree(pstrMessage);
+ }
}
return result;