Fix bugs detected by coverity

:Release Notes:
Close potentially leaked descriptors.
Fix incorrect sizeof.
Dereference after null check.
Logically dead code.

:Detailed Notes:

:Testing Performed:
Build succeeded. Unit tests.

:QA Notes:

:Issues Addressed:
[GF-51891] LS2: Fix bugs detected by coverity

Open-webOS-DCO-1.0-Signed-off-by: Anatolii Sakhnik <anatolii.sakhnik@lge.com>

Change-Id: Ia4e45824d8555b36442037a7989119e369b2cdf3
Reviewed-on: https://g2g.palm.com/3953
Reviewed-by: DCO Verification
Reviewed-by: Anatolii Sakhnik <anatolii.sakhnik@lge.com>
Tested-by: Anatolii Sakhnik <anatolii.sakhnik@lge.com>
Reviewed-by: Keith Derrick <keith.derrick@lge.com>
Tested-by: Keith Derrick <keith.derrick@lge.com>