[RFC] Coverity Issues

This PR fixes several Coverity issues listed in #760 , namely 13796, 62607, 62608, 62609, 62612, 62615. Additionally I found that some of the Coverity defects are false positives, especially in the ressource leak category.

I couldn't find how to mark them as false positives in the Coverity web interface though. I suspect that my role of contributer doesn't have sufficient rights to do so.
Is this really the logic you want?  It translates into:

    (!new_len) <= SIZE_MAX

which would then translate into either `0 <= SIZE_MAX` or `1 <= SIZE_MAX`, no?  Or am I missing something here?