*fixed a memory leak when reassigning an array element with string.
This commit is contained in:
parent
3630e237f5
commit
d89d018823
3
HISTORY
3
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
|
Feb. 2 2019
|
||||||
Fixed some crash and hanging with invalid expression and routine, thanks to siraben for pointing it out
|
Fixed some crash and hanging with invalid expression and routine, thanks to siraben for pointing it out
|
||||||
|
|
||||||
|
@ -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);
|
_handle_error_on_obj(s, SE_RN_STRING_EXPECTED, s->source_file, DON(ast), MB_FUNC_ERR, _exit, result);
|
||||||
}
|
}
|
||||||
_sl = strlen(val->string);
|
_sl = strlen(val->string);
|
||||||
|
if(*((char**)rawptr))
|
||||||
|
mb_free(*((char**)rawptr));
|
||||||
*((char**)rawptr) = (char*)mb_malloc(_sl + 1);
|
*((char**)rawptr) = (char*)mb_malloc(_sl + 1);
|
||||||
memcpy(*((char**)rawptr), val->string, _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;
|
break;
|
||||||
}
|
}
|
||||||
#else /* MB_SIMPLE_ARRAY */
|
#else /* MB_SIMPLE_ARRAY */
|
||||||
|
if(arr->types[index] == _DT_STRING && *((char**)rawptr))
|
||||||
|
mb_free(*((char**)rawptr));
|
||||||
switch(*type) {
|
switch(*type) {
|
||||||
case _DT_STRING: {
|
case _DT_STRING: {
|
||||||
size_t _sl = 0;
|
size_t _sl = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user