summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-06-28 13:28:42 -0300
committershennetsind <ind@henn.et>2013-06-28 13:28:42 -0300
commit203e44e51c8cb133bf3fb20b372d16ea92be7667 (patch)
tree7bdd8f9a75cbe3df2d17a03021139254d85c2d5e /src/map
parent852aaacc10faf384ab17c75fc386bb7491d09bd2 (diff)
downloadhercules-203e44e51c8cb133bf3fb20b372d16ea92be7667.tar.gz
hercules-203e44e51c8cb133bf3fb20b372d16ea92be7667.tar.bz2
hercules-203e44e51c8cb133bf3fb20b372d16ea92be7667.tar.xz
hercules-203e44e51c8cb133bf3fb20b372d16ea92be7667.zip
Fixed Bug #7448
Queue Iterators now keep a copy of the queue they'll iterate, so the iterator won't break items are removed or added during iteration. Special Thanks to Wend~! http://hercules.ws/board/tracker/issue-7448-queue-memory-leak/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 4ceb32991..5cc48c7ce 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -17051,8 +17051,14 @@ BUILDIN(queuesize) {
if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) {
ShowWarning("buildin_queuesize: unknown queue id %d\n",idx);
script_pushint(st, 0);
- } else
- script_pushint(st, script->hq[ idx ].items );
+ } else {
+ /* value of script->hq[].items isn't to be trusted for we dont reduce the size when members are removed to save on memory allocation */
+ int i, count = 0;
+ for( i = 0; i < script->hq[ idx ].items; i++ )
+ if( script->hq[ idx ].item[i] != -1 )
+ count++;
+ script_pushint(st, count);
+ }
return true;
}
@@ -17119,13 +17125,13 @@ bool script_hqueue_remove(int idx, int var) {
for(i = 0; i < script->hq[idx].items; i++) {
if( script->hq[idx].item[i] == var ) {
- return true;
+ break;
}
}
if( i != script->hq[idx].items ) {
struct map_session_data *sd;
- script->hq[idx].item[i] = 0;
+ script->hq[idx].item[i] = -1;
if( var >= START_ACCOUNT_NUM && (sd = iMap->id2sd(var)) ) {
for(i = 0; i < sd->queues_count; i++) {
@@ -17240,7 +17246,7 @@ BUILDIN(queueiterator) {
int idx = script->hqis;
int i;
- if( qid < 0 || qid >= script->hqs || script->hq[idx].items == -1 || !(queue = script->queue(qid)) ) {
+ if( qid < 0 || qid >= script->hqs || script->hq[qid].items == -1 || !(queue = script->queue(qid)) ) {
ShowWarning("queueiterator: invalid queue id %d\n",qid);
return true;
}
@@ -17258,8 +17264,8 @@ BUILDIN(queueiterator) {
idx = i;
RECREATE(script->hqi[ idx ].item, int, queue->items);
-
- memcpy(&script->hqi[idx].item, &queue->item, sizeof(int)*queue->items);
+
+ memcpy(script->hqi[idx].item, queue->item, sizeof(int)*queue->items);
script->hqi[ idx ].items = queue->items;
script->hqi[ idx ].pos = 0;