Fix error handling for mrb_generate_code().

The return value of mrb_generate_code()
must be null-checked before referencing.
Merge pull request #2541 from cubicdaiya/issues/codegen_error_handling

Fix error handling for mrb_generate_code().