Fixed many memory leaks, mostly in error branches

Various early return branches were not freeing memory.
Caught by 'cppcheck' tool.

Change-Id: I1840fd1a95aceb31275c35d4a004769333e3c17c
Fixed many memory leaks, mostly in error branches.

Most leaks fixed by adding deallocation in the early exit branch,
some fixed by rearranging code to put the early exit before the
allocation. Also removed some unnecessary checks for null before
using delete.

Presumably none of these branches are covered by tests,
or valgrind would find the leaks.  cppcheck found them though!

Change-Id: Iecad8ca988abc560939d46bf0a5a9e7e5a1511a5
Fixed undefined use of uninitialized variable

Change-Id: Ib8d051c590628aec66335bb5de0c7c7af9f35254
Fixed memory leaks in error branches by rearranging order.

Rearranged code to put the early exit before the
allocation.

Found with cppcheck.

Change-Id: I8320d0be9269375302fc80b788f00c1f3aeca989
Added missing fclose() calls in error branches

Several error branches were missing fclose() calls
to balance earlier fopen() calls.

Fixed a couple of leaks also in these same
error branches.

Found by cppcheck.

Change-Id: I7ed3bce1f0fb399c2ab1c3d6e6eac3518d845b17
Fixed cppcheck warning about null dereference

Move deref of pointer into branch that previously
checked that it isn't null.

Change-Id: Ia1b42d80e56a2d4700c899f3c5ef7c3db502134e
Fixed many memory leaks in error branches.

Leaks fixed by adding deallocation in the early exit branch.
Also removed some unnecessary checks for null before
using delete.

Found by cppcheck.

Change-Id: I8ec80d676926d9725999034846f52d0efb0c8da4
Merge topic 'cppcheck-leaks' into master

f5588ef8 Fixed many memory leaks in error branches.
f6074be3 Fixed cppcheck warning about null dereference
ccd03ca0 Added missing fclose() calls in error branches
e3bfbb77 Fixed memory leaks in error branches by rearranging order.
cad374c6 Fixed undefined use of uninitialized variable
9925eca3 Fixed many memory leaks, mostly in error branches.
192ea707 Fixed many memory leaks, mostly in error branches