Fixed broken NULL pointer check.
Fixed uninitialized value.
Fixed uninitialized values in case of error return.
Fixed uninitialized value.
Fixed missing NULL pointer check.
Fixed memory leak.
Fixed memory leak.
Fixed missing declarations.
Merge pull request #2261 from akallabeth/more_memleak_fixes

More warning and memleak fixes