C Target: mem leak and merge conflict fixes

The pull request seems to include also the upstream merge. However this doesn't change anything, so this pull request is only about the few mentioned changes.