aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand Jacquin (Beber) <beber@setibzh.com>2006-01-22 23:54:26 +0100
committerBertrand Jacquin (Beber) <beber@setibzh.com>2006-01-22 23:54:26 +0100
commit33e0c7594681fa67fef2282246c6e15cf7cbe63f (patch)
treea3be64dac6c7ca1ebcadfe1b912fb08697667990
parentfreeeee (diff)
downloadespik-33e0c7594681fa67fef2282246c6e15cf7cbe63f.tar.xz
add a espik_free to avoid mem leakdebut-espik-free
-rw-r--r--src/espik.c39
-rw-r--r--src/espik.h4
-rw-r--r--src/espik_config.c18
-rw-r--r--src/espik_net.c32
4 files changed, 56 insertions, 37 deletions
diff --git a/src/espik.c b/src/espik.c
index 0cee0c6..f991095 100644
--- a/src/espik.c
+++ b/src/espik.c
@@ -8,6 +8,7 @@
#include <Ecore.h>
#include <Ecore_Config.h> /* Configuration lib */
/*#include <Ecore_Con.h> */ /* Socket lib */
+#include <Ecore_Data.h> /* List */
/* Espik Stuff */
#include "espik.h"
@@ -24,8 +25,26 @@ typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
typedef int (*Handler_Fd_Func) (void *data, Ecore_Fd_Handler * fd_handler);
*/
-/* Use to replace EOL ('\n') with NULL ('\0') */
+static void espik_init()
+{
+ ptr_list = ecore_list_new();
+}
+
+static void espik_destroy_ptr(void *ptr)
+{
+ if (ptr)
+ {
+ espik_debug_print("Freeing data...");
+ free (ptr);
+ }
+}
+void espik_free (void *ptr)
+{
+ ecore_list_append (ptr_list, ptr);
+}
+
+/* Use to replace EOL ('\n') with NULL ('\0') */
int del_backslash (char *msg)
{
int i, count;
@@ -53,9 +72,10 @@ int main (int argc, char **argv)
espik_enter();
printf ("Welcome to %s %s\n", APPS_NAME, ESPIK_VERSION);
+ espik_init();
#ifdef _ESPIK_DEBUG_
- espik_debug_init();
+ //espik_debug_init();
#endif
if (!ecore_init ())
{
@@ -63,6 +83,7 @@ int main (int argc, char **argv)
exit (-1);
}
+ ecore_list_set_free_cb(ptr_list, espik_destroy_ptr);
espik_config_init ();
if (argc < 3)
@@ -86,7 +107,6 @@ int main (int argc, char **argv)
printf ("user: %s\n", a_infos.client->username);
printf ("real: %s\n", a_infos.client->realname);
-
#if 0
con_sock =
ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
@@ -103,6 +123,7 @@ int main (int argc, char **argv)
/* Handler Network & Keyboard */
fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, kb_get,
NULL, NULL, NULL);
+ espik_free(kb_get);
if (!fd_kb)
{
printf ("Cannot ecore_main_fd_handler_add\n");
@@ -123,18 +144,15 @@ int main (int argc, char **argv)
/*
ecore_con_server_del (con_sock);
- */
-// free (a_infos.server->host);
-// free (a_infos.server);
+ free (a_infos.server->host);
+ free (a_infos.server);
- /*
free (a_infos.client->nickname);
free (a_infos.client->username);
free (a_infos.client->realname);
+ free (a_infos.client);
*/
-// free (a_infos.client);
-
espik_debug_print ("end");
@@ -144,9 +162,8 @@ int main (int argc, char **argv)
espik_con_shutdown ();
*/
-// ecore_main_loop_quit ();
ecore_shutdown ();
+ ecore_list_destroy(ptr_list);
- //espik_leave();
return (0);
}
diff --git a/src/espik.h b/src/espik.h
index 639a791..2c4f84d 100644
--- a/src/espik.h
+++ b/src/espik.h
@@ -1,6 +1,8 @@
#ifndef HAVE_ESPIK_H
#define HAVE_ESPIK_H
+#include <Ecore_Data.h>
+
typedef struct
{
char* host;
@@ -21,7 +23,9 @@ typedef struct
} t_info;
t_info a_infos;
+Ecore_List *ptr_list;
+void espik_free (void*);
int del_backslash (char*);
int main (int, char**);
diff --git a/src/espik_config.c b/src/espik_config.c
index 0cbc0d3..6587b98 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -47,8 +47,8 @@ t_userinfo* espik_user_sysinfo_get ()
else
u_info->realname = strdup (pw->pw_gecos);
- /* FIXME: segv */
- free (pw);
+ espik_free (u_info);
+ espik_free (pw);
espik_leave();
return (u_info);
@@ -73,7 +73,10 @@ void espik_config_default_set ()
ecore_config_string_default ("/espik/version", ESPIK_VERSION);
- free (user_sysinfo);
+ espik_free (user_sysinfo->nickname);
+ espik_free (user_sysinfo->username);
+ espik_free (user_sysinfo->realname);
+ espik_free (user_sysinfo);
espik_leave();
}
@@ -106,13 +109,10 @@ void espik_config_init ()
void espik_config_shutdown (t_info s_info)
{
- free (s_info.server->host);
+ espik_free (s_info.server->host);
// free (s_info->server->port);
- free (s_info.server);
- free (s_info.client->nickname);
- free (s_info.client->username);
- free (s_info.client->realname);
- free (s_info.client);
+ espik_free (s_info.server);
+ espik_free (s_info.client);
// free (s_info);
ecore_config_save();
diff --git a/src/espik_net.c b/src/espik_net.c
index 679ee04..d56f070 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -16,21 +16,12 @@
typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
-static int ret; /* For debug */
+static int ret_int; /* For debug */
char connected = 0;
Ecore_Con_Server* con_sock;
-typedef struct
-{
- Ecore_Event_Handler* data;
- Ecore_Event_Handler* up;
- Ecore_Event_Handler* down;
-
-} espik_con_handler_list;
-
-
-espik_con_handler_list handler_list;
+Ecore_Event_Handler* ret;
void espik_con_init (t_info serv_info)
{
@@ -54,30 +45,35 @@ void espik_con_init (t_info serv_info)
"(ECORE_CON_REMOTE_SYSTEM)");
exit (-1);
}
+ espik_free (con_sock);
- if (! (handler_list.data = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
+ if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
(Handler_Func) server_data, NULL)))
{
espik_debug_print ("ecore_event_handler_add "
"(ECORE_CON_EVENT_SERVER_DATA)");
exit (-1);
}
+ espik_free (ret);
- if (! (handler_list.up = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD,
+ if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD,
(Handler_Func) espik_con_up, NULL)))
{
espik_debug_print ("ecore_event_handler_add "
"(ECORE_CON_EVENT_SERVER_ADD)");
exit (-1);
}
+ espik_free (ret);
- if (! (handler_list.down = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL,
+ if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL,
(Handler_Func) espik_con_shutdown, NULL)))
{
espik_debug_print ("ecore_event_handler_add "
"(ECORE_CON_EVENT_SERVER_DEL)");
exit (-1);
}
+ espik_free (ret);
+
espik_leave();
}
@@ -136,12 +132,14 @@ void espik_con_shutdown ()
ecore_con_shutdown ();
+ /*
ecore_event_handler_del (handler_list.data);
ecore_event_handler_del (handler_list.up);
ecore_event_handler_del (handler_list.down);
+ */
ecore_main_loop_quit ();
- free (server_dns);
+ espik_free (server_dns);
espik_leave();
}
@@ -174,9 +172,9 @@ void espik_raw_send (const char *msg)
}
- ret = ecore_con_server_send (con_sock, buf.buf, buf.len);
+ ret_int = ecore_con_server_send (con_sock, buf.buf, buf.len);
- espik_debug_print ("ret: %d", ret);
+ espik_debug_print ("ret_int: %d", ret_int);
free (buf.buf);
// free (msg);
espik_leave();