From 0461197d573f0d38c3ce2c7e6ba55cb8c5727d42 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 19 Aug 2005 13:44:02 +0000 Subject: correction bug malloc free --- src/ivy.c | 12 +++++++----- src/ivybind.c | 10 ++++++++-- src/ivysocket.c | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ivy.c b/src/ivy.c index d4b4880..b1777fe 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -524,8 +524,8 @@ static char* Receive( Client client, void *data, char *message, unsigned int len const char *errbuf; IvyBindingGetCompileError( &offset, &errbuf ); MsgSendTo( client, Error, offset, strlen(errbuf), errbuf ); + free( str_regexp ); } - free( str_regexp ); break; case DelBinding: @@ -1074,8 +1074,8 @@ int IvySendMsg(const char *fmt, ...) { IvyClientPtr clnt; int match_count = 0; - static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ - static int size = 0; /* donc non reentrant !!!! */ + char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ + int size = 0; /* donc non reentrant !!!! */ va_list ap; va_start( ap, fmt ); @@ -1089,19 +1089,21 @@ int IvySendMsg(const char *fmt, ...) #ifdef DEBUG if ( match_count == 0 ) printf( "Warning no recipient for %s\n",buffer); #endif + free(buffer); return match_count; } void IvySendError( IvyClientPtr app, int id, const char *fmt, ... ) { - static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ - static int size = 0; /* donc non reentrant !!!! */ + char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ + int size = 0; /* donc non reentrant !!!! */ va_list ap; va_start( ap, fmt ); make_message( &buffer, &size, 0, fmt, ap ); va_end ( ap ); MsgSendTo( app->client, Error, id, strlen(buffer), buffer); + free(buffer); } void IvyBindDirectMsg( MsgDirectCallback callback, void *user_data) diff --git a/src/ivybind.c b/src/ivybind.c index 9d95e92..237ee78 100644 --- a/src/ivybind.c +++ b/src/ivybind.c @@ -49,7 +49,6 @@ static int err_offset; #endif struct _binding { - struct _binding *next; IvyBindingType type; const char *msgname; /* msg tag name first word of message */ char **msgargs; /* list of msg argument name */ @@ -93,6 +92,8 @@ static IvyBinding IvyBindingCompileSimple( IvyBindingType typ, const char * expr } bind = (IvyBinding)malloc( sizeof( struct _binding )); + memset( bind, 0, sizeof(*bind ) ); + bind->type = IvyBindSimple; bind->msgname = strtok( expr, " "); bind->msgargs = malloc ( sizeof( char* ) * ( nb_arg + 1) ); argv = bind->msgargs; @@ -110,8 +111,8 @@ static IvyBinding IvyBindingCompileRegexp( IvyBindingType typ, const char * expr if ( regexp != NULL ) { bind = (IvyBinding)malloc( sizeof( struct _binding )); + memset( bind, 0, sizeof(*bind ) ); bind->regexp = regexp; - bind->next = NULL; bind->type = IvyBindRegexp; bind->inspect = pcre_study(regexp,0,&err_buf); if (err_buf!=NULL) @@ -130,6 +131,7 @@ static IvyBinding IvyBindingCompileRegexp( IvyBindingType typ, const char * expr if ( reg == 0 ) { bind = (IvyBinding)malloc( sizeof( struct _binding )); + memset( bind, 0, sizeof(*bind ) ); bind->regexp = regexp; bind->next = NULL; } @@ -161,6 +163,10 @@ void IvyBindingFree( IvyBinding bind ) pcre_free(bind->regexp); #else #endif + if (bind->msgname) + free ( bind->msgname ); + if (bind->msgargs) + free ( bind->msgargs ); free ( bind ); } int IvyBindingExecRegexp( IvyBinding bind, const char * message ) diff --git a/src/ivysocket.c b/src/ivysocket.c index d2f3259..9ff66a0 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -303,6 +303,7 @@ void SocketServerClose (Server server ) if (!server) return; IvyChannelRemove( server->channel ); + IVY_LIST_REMOVE (servers_list, server ); } char *SocketGetPeerHost (Client client ) -- cgit v1.1