widgets: improve error handling and cleanup

Variables are initialized, pointers are validated before being freed,
most widgets now have a cleanup label which handles cleanup if any
errors occur during widget initialization.