summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgreenboxal2 <greenboxal2@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-04-24 16:27:04 +0000
committergreenboxal2 <greenboxal2@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-04-24 16:27:04 +0000
commita5244368bb4c8887d900228658f4fa680222d0da (patch)
tree3b29ef1eb50674abb4005dda2b362675da5d43eb
parent173905288bdb123e7c2249f9d05714acf2f1541a (diff)
downloadhercules-a5244368bb4c8887d900228658f4fa680222d0da.tar.gz
hercules-a5244368bb4c8887d900228658f4fa680222d0da.tar.bz2
hercules-a5244368bb4c8887d900228658f4fa680222d0da.tar.xz
hercules-a5244368bb4c8887d900228658f4fa680222d0da.zip
Fixed memory leak on MvP tomb system, killer name now uses static buffer. (bugreport:5615)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15954 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--src/map/mob.c9
-rw-r--r--src/map/mob.h4
-rw-r--r--src/map/npc.c2
-rw-r--r--src/map/npc.h2
-rw-r--r--src/map/unit.c2
5 files changed, 10 insertions, 9 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index a32ba3c64..6790d5e92 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -151,9 +151,9 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time)
nd->u.tomb.kill_time = time;
if (killer)
- nd->u.tomb.killer_name = aStrdup(killer); // Don't rely that killer name will be available all time
+ safestrncpy(nd->u.tomb.killer_name, killer, NAME_LENGTH);
else
- nd->u.tomb.killer_name = NULL;
+ nd->u.tomb.killer_name[0] = NULL;
map_addnpc(nd->bl.m, nd);
map_addblock(&nd->bl);
@@ -168,12 +168,7 @@ void mvptomb_destroy(struct mob_data *md)
struct npc_data *nd = (struct npc_data *)map_id2bl(md->tomb_nid);
if (nd)
- {
- if (nd->u.tomb.killer_name)
- aFree(nd->u.tomb.killer_name);
-
npc_unload(nd);
- }
md->tomb_nid = 0;
}
diff --git a/src/map/mob.h b/src/map/mob.h
index 4caf0148c..12c05b15d 100644
--- a/src/map/mob.h
+++ b/src/map/mob.h
@@ -287,4 +287,8 @@ int mob_clone_delete(struct mob_data *md);
void mob_reload(void);
+// MvP Tomb System
+void mvptomb_create(struct mob_data *md, char *killer, time_t time);
+void mvptomb_destroy(struct mob_data *md);
+
#endif /* _MOB_H_ */
diff --git a/src/map/npc.c b/src/map/npc.c
index d0defdf88..0309d6556 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1097,7 +1097,7 @@ void run_tomb(struct map_session_data* sd, struct npc_data* nd)
clif_scriptmes(sd, nd->bl.id, msg_txt(660));
- snprintf(buffer, sizeof(buffer), msg_txt(661), nd->u.tomb.killer_name ? nd->u.tomb.killer_name : "Unknown");
+ snprintf(buffer, sizeof(buffer), msg_txt(661), nd->u.tomb.killer_name[0] ? nd->u.tomb.killer_name : "Unknown");
clif_scriptmes(sd, nd->bl.id, buffer);
clif_scriptclose(sd, nd->bl.id);
diff --git a/src/map/npc.h b/src/map/npc.h
index 47f6117d9..81491eeb3 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -65,7 +65,7 @@ struct npc_data {
struct {
struct mob_data *md;
time_t kill_time;
- char *killer_name;
+ char killer_name[NAME_LENGTH];
} tomb;
} u;
};
diff --git a/src/map/unit.c b/src/map/unit.c
index 43cbc02e1..7718ed311 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2368,6 +2368,8 @@ int unit_free(struct block_list *bl, clr_type clrtype)
}
if( mob_is_clone(md->class_) )
mob_clone_delete(md);
+ if( md->tomb_nid )
+ mvptomb_destroy(md);
break;
}
case BL_HOM: