ctrlcmd->value      = pfmt;
   ctrlcmd->timeout_ms = 10000;
 
-       if (pfmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+       if (pfmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+               kfree(ctrlcmd);
                return -1;
+       }
 
 #if 0
        /* FIXEME */
-       if (pfmt->fmt.pix.pixelformat != V4L2_PIX_FMT_YVU420)
+       if (pfmt->fmt.pix.pixelformat != V4L2_PIX_FMT_YVU420) {
+               kfree(ctrlcmd);
                return -EINVAL;
+       }
 #endif
 
        /* Ok, but check other params, too. */
 
        /* fill message with right content. */
        /* @todo This is causing issues, need further investigate */
        /* spin_lock_irqsave(&ctrl->state_lock, flags); */
-       if (ctrl->vstate != VFE_STATE_ACTIVE)
+       if (ctrl->vstate != VFE_STATE_ACTIVE) {
+               kfree(msg);
                goto af_stats_done;
+       }
 
        msg->_d = VFE_MSG_ID_STATS_AUTOFOCUS;
        msg->_u.msgStatsAf.afBuffer = afBufAddress;
        /* fill message with right content. */
        /* @todo This is causing issues, need further investigate */
        /* spin_lock_irqsave(&ctrl->state_lock, flags); */
-       if (ctrl->vstate != VFE_STATE_ACTIVE)
+       if (ctrl->vstate != VFE_STATE_ACTIVE) {
+               kfree(msg);
                goto awb_stats_done;
+       }
 
        msg->_d = VFE_MSG_ID_STATS_WB_EXP;
        msg->_u.msgStatsWbExp.awbBuffer = awbBufAddress;
        /* fill message with right content. */
        /* @todo This is causing issues, need further investigate */
        /* spin_lock_irqsave(&ctrl->state_lock, flags); */
-       if (ctrl->vstate != VFE_STATE_ACTIVE)
+       if (ctrl->vstate != VFE_STATE_ACTIVE) {
+               kfree(msg);
                goto output2_msg_done;
+       }
 
        msg->_d = VFE_MSG_ID_OUTPUT2;
 
 
        /* @todo This is causing issues, need further investigate */
        /* spin_lock_irqsave(&ctrl->state_lock, flags); */
-       if (ctrl->vstate != VFE_STATE_ACTIVE)
+       if (ctrl->vstate != VFE_STATE_ACTIVE) {
+               kfree(msg);
                goto output1_msg_done;
+       }
 
        msg->_d = VFE_MSG_ID_OUTPUT1;
        memmove(&(msg->_u),