Pull constructor error checking

This patch series adds lots of error checking:
- constructors free all resources and return NULL on error (instead of asserting)
- functions undo and return an error when a sub function gave an error
- assert when an error can't be returned or is impractical
- assert every constructor call in tests

I went through all files so this should be pretty complete. There where a few cases where I couldn't return an error from a sub function because the function itself returns void. This should be fixed but changes the api. In a few other cases returning an error was too complex. In those cases I used assert to at least catch the error where it occurs.