From 0da3671876a62ff48b990990e2e1723865bc8cd7 Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Sun, 30 Dec 2007 21:14:09 +0000 Subject: * Fixed get_val2 not using the stack, which automatically frees the data, causing memory leaks for string variables since r11976. (bugreport:723 , part of bugreport:714 and part of bugreport:708) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11997 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/script.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index 12f9b9313..8b7135e40 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2233,15 +2233,17 @@ void get_val(struct script_state* st, struct script_data* data) return; } +void push_val2(struct script_stack* stack, int type, int val, struct linkdb_node** ref); + /// Retrieves the value of a reference identified by uid (variable, constant, param) +/// The value is left in the top of the stack and needs to be removed manually. void* get_val2(struct script_state* st, int uid, struct linkdb_node** ref) { - struct script_data data; - data.type = C_NAME; - data.u.num = uid; - data.ref = ref; - get_val(st, &data); - return (data.type == C_INT ? (void*)data.u.num : (void*)data.u.str); + struct script_data* data; + push_val2(st->stack, C_NAME, uid, ref); + data = script_getdatatop(st, -1); + get_val(st, data); + return (data->type == C_INT ? (void*)data->u.num : (void*)data->u.str); } /*========================================== @@ -4735,6 +4737,7 @@ static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isst char* str = (char*)get_val2(st, reference_uid(id, idx), ref); if( str && *str ) ret = idx + 1; + script_removetop(st, -1, 0); } } else @@ -4744,6 +4747,7 @@ static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isst int32 num = (int32)get_val2(st, reference_uid(id, idx), ref); if( num ) ret = idx + 1; + script_removetop(st, -1, 0); } } return ret; @@ -4941,6 +4945,7 @@ BUILDIN_FUNC(copyarray) { v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); + script_removetop(st, -1, 0); } } else @@ -4948,10 +4953,13 @@ BUILDIN_FUNC(copyarray) for( i = 0; i < count; ++i ) { if( idx2 + i < 128 ) + { v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); + set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); + script_removetop(st, -1, 0); + } else// out of range - assume ""/0 - v = (void*)(is_string_variable(name1) ? "" : 0); - set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); + set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1)); } } return 0; @@ -5049,6 +5057,7 @@ BUILDIN_FUNC(deletearray) { void* v = get_val2(st, reference_uid(id, start + count), reference_getref(data)); set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data)); + script_removetop(st, -1, 0); } } -- cgit v1.2.3-60-g2f50