python: add proper error handling to loaded_modules()

We need to check the result of basically all Py* calls and cleanup
properly if they fail.
1 file changed