summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorcelest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-03-23 15:26:52 +0000
committercelest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-03-23 15:26:52 +0000
commit33b8fd47955eeab26cede233b14d683b8e0491b8 (patch)
tree041f7df2acc8b46bdb56512f06b0f9706fe6ec29 /src/char
parent7d3fedfa5c264169c544fe3ec977229c50e4baa2 (diff)
downloadhercules-33b8fd47955eeab26cede233b14d683b8e0491b8.tar.gz
hercules-33b8fd47955eeab26cede233b14d683b8e0491b8.tar.bz2
hercules-33b8fd47955eeab26cede233b14d683b8e0491b8.tar.xz
hercules-33b8fd47955eeab26cede233b14d683b8e0491b8.zip
* Fixed alot of memory leaks
* Added stray memory cleaning routine to db.c git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1275 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char')
-rw-r--r--src/char/char.c12
-rw-r--r--src/char/int_guild.c20
-rw-r--r--src/char/int_guild.h1
-rw-r--r--src/char/int_party.c11
-rw-r--r--src/char/int_party.h1
-rw-r--r--src/char/int_pet.c11
-rw-r--r--src/char/int_pet.h1
-rw-r--r--src/char/int_storage.c16
-rw-r--r--src/char/int_storage.h1
-rw-r--r--src/char/inter.c23
-rw-r--r--src/char/inter.h1
11 files changed, 89 insertions, 9 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 1a2b61389..78f4bd3ae 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -22,6 +22,7 @@
#include "socket.h"
#include "timer.h"
#include "mmo.h"
+#include "db.h"
#include "version.h"
#include "lock.h"
#include "char.h"
@@ -630,11 +631,6 @@ int mmo_char_init(void) {
printf("out of memory: mmo_char_init (calloc of char_dat).\n");
exit(1);
}
- online_chars = (struct online_chars*)aCalloc(sizeof(struct online_chars) * 256, 1);
- if (!online_chars) {
- printf("out of memory: mmo_char_init (calloc of online_chars).\n");
- exit(1);
- }
for(i = 0; i < char_max; i++)
{
online_chars[i].char_id = -1;
@@ -3456,8 +3452,9 @@ void do_final(void) {
delete_session(login_fd);
delete_session(char_fd);
- for(i = 0; i < fd_max; i++)
- if(session[i] != NULL) aFree(session[i]);
+ inter_final();
+ exit_dbn();
+ timer_final();
char_log("----End of char-server (normal end with closing of all files)." RETCODE);
}
@@ -3512,7 +3509,6 @@ int do_init(int argc, char **argv) {
online_chars[i].server = -1;
}
-
mmo_char_init();
update_online = time(NULL);
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 267b66f0f..78e6b476f 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -488,10 +488,28 @@ int inter_guild_init() {
return 0;
}
+int castle_db_final (void *k, void *data, va_list ap)
+{
+ struct guild_castle *gc = data;
+ if (gc) aFree(gc);
+ return 0;
+}
+int guild_db_final (void *k, void *data, va_list ap)
+{
+ struct guild *g = data;
+ if (g) aFree(g);
+ return 0;
+}
+void inter_guild_final() {
+ numdb_final(castle_db, castle_db_final);
+ numdb_final(guild_db, guild_db_final);
+ return;
+}
+
struct guild *inter_guild_search(int guild_id) {
struct guild *g;
- g= (struct guild *) numdb_search(guild_db, guild_id);
+ g = (struct guild *) numdb_search(guild_db, guild_id);
return g;
}
diff --git a/src/char/int_guild.h b/src/char/int_guild.h
index 555f5e123..3eeb1b3db 100644
--- a/src/char/int_guild.h
+++ b/src/char/int_guild.h
@@ -3,6 +3,7 @@
#define _INT_GUILD_H_
int inter_guild_init();
+void inter_guild_final();
int inter_guild_save();
int inter_guild_parse_frommap(int fd);
struct guild *inter_guild_search(int guild_id);
diff --git a/src/char/int_party.c b/src/char/int_party.c
index 3298587f1..5ee48fc70 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -117,6 +117,17 @@ int inter_party_init() {
return 0;
}
+int party_db_final (void *k, void *data, va_list ap) {
+ struct party *p = data;
+ if (p) aFree(p);
+ return 0;
+}
+void inter_party_final()
+{
+ numdb_final(party_db, party_db_final);
+ return;
+}
+
// パ?ティ?デ?タのセ?ブ用
int inter_party_save_sub(void *key, void *data, va_list ap) {
char line[8192];
diff --git a/src/char/int_party.h b/src/char/int_party.h
index b265b4c2e..e3180f3b7 100644
--- a/src/char/int_party.h
+++ b/src/char/int_party.h
@@ -3,6 +3,7 @@
#define _INT_PARTY_H_
int inter_party_init();
+void inter_party_final();
int inter_party_save();
int inter_party_parse_frommap(int fd);
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index 8682860c0..342854f8b 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -109,6 +109,17 @@ int inter_pet_init()
return 0;
}
+int pet_db_final (void *k, void *data, va_list ap) {
+ struct s_pet *p = data;
+ if (p) aFree(p);
+ return 0;
+}
+void inter_pet_final()
+{
+ numdb_final(pet_db, pet_db_final);
+ return;
+}
+
int inter_pet_save_sub(void *key,void *data,va_list ap)
{
char line[8192];
diff --git a/src/char/int_pet.h b/src/char/int_pet.h
index 993f913ab..3a48ada3b 100644
--- a/src/char/int_pet.h
+++ b/src/char/int_pet.h
@@ -3,6 +3,7 @@
#define _INT_PET_H_
int inter_pet_init();
+void inter_pet_final();
int inter_pet_save();
int inter_pet_delete(int pet_id);
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index 3c5695c90..67b25909b 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -291,6 +291,22 @@ int inter_storage_init()
return 0;
}
+int storage_db_final (void *k, void *data, va_list ap) {
+ struct storage *p = data;
+ if (p) aFree(p);
+ return 0;
+}
+int guild_storage_db_final (void *k, void *data, va_list ap) {
+ struct guild_storage *p = data;
+ if (p) aFree(p);
+ return 0;
+}
+void inter_storage_final() {
+ numdb_final(storage_db, storage_db_final);
+ numdb_final(guild_storage_db, guild_storage_db_final);
+ return;
+}
+
int inter_storage_save_sub(void *key,void *data,va_list ap)
{
char line[65536];
diff --git a/src/char/int_storage.h b/src/char/int_storage.h
index d918f5fe3..f228be53d 100644
--- a/src/char/int_storage.h
+++ b/src/char/int_storage.h
@@ -3,6 +3,7 @@
#define _INT_STORAGE_H_
int inter_storage_init();
+void inter_storage_final();
int inter_storage_save();
int inter_guild_storage_save();
int inter_storage_delete(int account_id);
diff --git a/src/char/inter.c b/src/char/inter.c
index f368a48b6..3a388ea82 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -261,6 +261,29 @@ int inter_init(const char *file) {
return 0;
}
+// finalize
+int accreg_db_final (void *k, void *data, va_list ap) {
+ struct accreg *p = data;
+ if (p) aFree(p);
+ return 0;
+}
+int wis_db_final (void *k, void *data, va_list ap) {
+ struct WisData *p = data;
+ if (p) aFree(p);
+ return 0;
+}
+void inter_final() {
+ numdb_final(accreg_db, accreg_db_final);
+ numdb_final(wis_db, wis_db_final);
+
+ inter_party_final();
+ inter_guild_final();
+ inter_storage_final();
+ inter_pet_final();
+
+ return;
+}
+
// マップサーバー接続
int inter_mapif_init(int fd) {
inter_guild_mapif_init(fd);
diff --git a/src/char/inter.h b/src/char/inter.h
index 0b6f809d7..636ce31d8 100644
--- a/src/char/inter.h
+++ b/src/char/inter.h
@@ -3,6 +3,7 @@
#define _INTER_H_
int inter_init(const char *file);
+void inter_final();
int inter_save();
int inter_parse_frommap(int fd);
int inter_mapif_init(int fd);