From 2a4d8d40cbd4853ca9d80e03164ccdcc30caa3c8 Mon Sep 17 00:00:00 2001 From: paladin-t Date: Mon, 30 Nov 2015 13:40:12 +0800 Subject: [PATCH] *improved stability for sub routine. --- HISTORY | 3 +++ core/my_basic.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index b7b2488..e040461 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Nov. 30 2015 +Improved stability for sub routine + Nov. 26 2015 Raised error for invalid routine usage Fixed a memory corruption bug when met an invalid routine usage diff --git a/core/my_basic.c b/core/my_basic.c index aeb3738..f575fd8 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -81,7 +81,7 @@ extern "C" { /** Macros */ #define _VER_MAJOR 1 #define _VER_MINOR 1 -#define _VER_REVISION 99 +#define _VER_REVISION 100 #define _VER_SUFFIX #define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION)) #define _STRINGIZE(A) _MAKE_STRINGIZE(A) @@ -2867,6 +2867,9 @@ int _eval_routine(mb_interpreter_t* s, _ls_node_t** l, mb_value_t* va, unsigned running = _push_scope(s, running); *l = r->entry; + if(!(*l)) { + _handle_error_on_obj(s, SE_RN_INVALID_ROUTINE, 0, DON(ast), MB_FUNC_ERR, _exit, result); + } do { result = _execute_statement(s, l); @@ -5547,8 +5550,10 @@ int _dispose_object(_object_t* obj) { case _DT_ROUTINE: if(!obj->ref) { safe_free(obj->data.routine->name); - _ht_foreach(obj->data.routine->scope->var_dict, _destroy_object); - _ht_destroy(obj->data.routine->scope->var_dict); + if(obj->data.routine->scope->var_dict) { + _ht_foreach(obj->data.routine->scope->var_dict, _destroy_object); + _ht_destroy(obj->data.routine->scope->var_dict); + } safe_free(obj->data.routine->scope); if(obj->data.routine->parameters) _ls_destroy(obj->data.routine->parameters);