python: avoid uninitialized pointer free
python: avoid use of uninitialized variable
python: don't overrun array read

classes[i+1] is uninitialized so it makes no sense to check for
NULL here. We ought to check classes[i] which we just allocated
from a function that can fail.
python: avoid use of initialized ptr
python: correct function guards

That was a verbatim copy-paste.
python: dereference after NULL-check
python: move up unreachable free()