From 33e0c7594681fa67fef2282246c6e15cf7cbe63f Mon Sep 17 00:00:00 2001 From: "Bertrand Jacquin (Beber)" Date: Sun, 22 Jan 2006 23:54:26 +0100 Subject: add a espik_free to avoid mem leak --- src/espik.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/espik.c') 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 #include /* Configuration lib */ /*#include */ /* Socket lib */ +#include /* 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); } -- cgit v1.2.3