Fixed coverity and other resource leak issues

Signed-off-by: Santhosh Edukulla <santhosh.edukulla@gmail.com>