summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-30 21:14:09 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-30 21:14:09 +0000
commit0da3671876a62ff48b990990e2e1723865bc8cd7 (patch)
tree96f4b97c8d77a210a14246fbd533c1ea134542ca
parent9a181f777daedf6708c777f33f893b3c7d60f381 (diff)
downloadhercules-0da3671876a62ff48b990990e2e1723865bc8cd7.tar.gz
hercules-0da3671876a62ff48b990990e2e1723865bc8cd7.tar.bz2
hercules-0da3671876a62ff48b990990e2e1723865bc8cd7.tar.xz
hercules-0da3671876a62ff48b990990e2e1723865bc8cd7.zip
* 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
-rw-r--r--Changelog-Trunk.txt3
-rw-r--r--src/map/script.c25
2 files changed, 20 insertions, 8 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index cfab32d1e..ff1a4900a 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/12/30
+ * 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)
* Trully fixed the previous commits. (missing cast and incomplete size)
* Made the memory manager set allocated memory to 0xCD and freed memory
to 0xDD. The memory manager no longer 'hides' uses of freed memory.
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);
}
}