diff --git a/HISTORY b/HISTORY index b64fdea..e3793ee 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Mar. 16 2019 +Fixed a memory leak when reassigning an array element with string, thanks to Jacques Diederik for pointing it out + Feb. 2 2019 Fixed some crash and hanging with invalid expression and routine, thanks to siraben for pointing it out diff --git a/core/my_basic.c b/core/my_basic.c index 0cced05..8c1317c 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -7373,6 +7373,8 @@ static int _set_array_elem(mb_interpreter_t* s, _ls_node_t* ast, _array_t* arr, _handle_error_on_obj(s, SE_RN_STRING_EXPECTED, s->source_file, DON(ast), MB_FUNC_ERR, _exit, result); } _sl = strlen(val->string); + if(*((char**)rawptr)) + mb_free(*((char**)rawptr)); *((char**)rawptr) = (char*)mb_malloc(_sl + 1); memcpy(*((char**)rawptr), val->string, _sl + 1); } @@ -7384,6 +7386,8 @@ static int _set_array_elem(mb_interpreter_t* s, _ls_node_t* ast, _array_t* arr, break; } #else /* MB_SIMPLE_ARRAY */ + if(arr->types[index] == _DT_STRING && *((char**)rawptr)) + mb_free(*((char**)rawptr)); switch(*type) { case _DT_STRING: { size_t _sl = 0;