Fix mem leaks.
Remove dead code.
Merge remote-tracking branch 'origin/topic/jsiwek/coverity'

* origin/topic/jsiwek/coverity:
  Remove dead code.
  Fix mem leaks.