diff --git a/.gitattributes b/.gitattributes index 0141268f..27296f0d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -566,6 +566,7 @@ src/win32/neostats.rc -text src/win32/resource.h -text src/win32/winmain.c -text tools/generate_header -text +tools/neostats.suppression -text tools/sqlphp/README -text tools/sqlphp/rta_tables.php -text tools/sqlphp/rta_view.php -text diff --git a/ChangeLog b/ChangeLog index 08a2bb42..c8b89a81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ Anything we add/remove/fix/change is in here (even our rants) Fish (F), Mark (M), DeadNotBuried (D) =============================================================================== * NeoStats * Version 3.0.a3-dev + - First round of memory cleanups with Valgrind (F) + - Create a runvalgrind.sh file with NeoStats suppressions for memory + checking (F) - Sync up libevent to distribution of 1.1a (F) - Make QuoteServ take a optional database for Quote Command (F) - Fix up triggering WANT_NICKIP code (F) diff --git a/lib/event/event.c b/lib/event/event.c index 0e1218ea..30f8ade8 100644 --- a/lib/event/event.c +++ b/lib/event/event.c @@ -178,6 +178,12 @@ event_init(void) return (current_base); } +int +event_fini(void) +{ + return event_priority_fini(current_base->nactivequeues); +} + int event_priority_init(int npriorities) { @@ -191,7 +197,6 @@ event_base_priority_init(struct event_base *base, int npriorities) if (base->event_count_active) return (-1); - if (base->nactivequeues && npriorities != base->nactivequeues) { for (i = 0; i < base->nactivequeues; ++i) { free(base->activequeues[i]); @@ -199,6 +204,7 @@ event_base_priority_init(struct event_base *base, int npriorities) free(base->activequeues); } + /* Allocate our priority queues */ base->nactivequeues = npriorities; base->activequeues = (struct event_list **)calloc(base->nactivequeues, @@ -216,6 +222,29 @@ event_base_priority_init(struct event_base *base, int npriorities) return (0); } +int +event_priority_fini(int npriorities) +{ + return event_base_priority_fini(current_base, npriorities); +} + +int +event_base_priority_fini(struct event_base *base, int npriorities) +{ + int i; + + if (base->event_count_active) + return (-1); + for (i = 0; i < base->nactivequeues; ++i) { + free(base->activequeues[i]); + } + free(base->activequeues); + free(base); + return (0); +} + + + int event_haveevents(struct event_base *base) { diff --git a/lib/event/event.h b/lib/event/event.h index 5316e7fc..a45d1f14 100644 --- a/lib/event/event.h +++ b/lib/event/event.h @@ -129,6 +129,8 @@ struct eventop { #define TIMEOUT_DEFAULT {5, 0} void *event_init(void); +int event_fini(void); + int event_dispatch(void); int event_base_dispatch(struct event_base *); @@ -190,7 +192,9 @@ const char *event_get_method(void); /* These functions deal with event priorities */ int event_priority_init(int); +int event_priority_fini(int); int event_base_priority_init(struct event_base *, int); +int event_base_priority_fini(struct event_base *, int); int event_priority_set(struct event *, int); /* These functions deal with buffering input and output */ diff --git a/modules/quoteserv/main.c b/modules/quoteserv/main.c index 8d9fa8fe..4d1d23e5 100644 --- a/modules/quoteserv/main.c +++ b/modules/quoteserv/main.c @@ -234,6 +234,7 @@ int ModFini( void ) database *db; hnode_t *hn; hscan_t hs; + int i; SET_SEGV_LOCATION(); hash_scan_begin( &hs, qshash ); @@ -241,6 +242,12 @@ int ModFini( void ) db =( ( database * )hnode_get( hn ) ); hash_delete( qshash, hn ); hnode_destroy( hn ); + ns_free(db->prefixstring); + ns_free(db->suffixstring); + for (i = 0; i < db->stringcount; i++) { + ns_free(db->stringlist[i]); + } + ns_free(db->stringlist); ns_free( db ); } hash_destroy( qshash ); diff --git a/src/dcc.c b/src/dcc.c index 7acd7df9..a5b5422c 100644 --- a/src/dcc.c +++ b/src/dcc.c @@ -327,4 +327,5 @@ void FiniDCC( void ) dccnode = list_next( dcclist, dccnode ); } list_destroy_nodes( dcclist ); + list_destroy(dcclist); } diff --git a/src/dl.c b/src/dl.c index 46bae3f7..ff60898f 100644 --- a/src/dl.c +++ b/src/dl.c @@ -104,12 +104,16 @@ void *ns_dlopen (const char *file, int mode) int ns_dlclose (void *handle) { +#ifndef VALGRIND #ifdef WIN32 FreeLibrary((HMODULE)handle); return 0; #else return (dlclose (handle)); #endif +#else + return NS_SUCCESS; +#endif } char *ns_dlerror (void) diff --git a/src/dns.c b/src/dns.c index 670f2ed1..5086d559 100644 --- a/src/dns.c +++ b/src/dns.c @@ -252,8 +252,7 @@ void FiniDns (void) list_destroy (dnsqueue); event_del(dnstimeout); free(dnstimeout); - - free(ads); + adns_finish(ads); } /** @brief Canx any DNS queries for modules we might be unloading * diff --git a/src/exclude.c b/src/exclude.c index ee471b68..709c89c6 100644 --- a/src/exclude.c +++ b/src/exclude.c @@ -105,6 +105,7 @@ int InitModExcludes(Module *mod_ptr) void FiniExcludes(void) { + DBACloseTable("exclusions"); list_destroy_auto (exclude_list); } diff --git a/src/ircprotocol.c b/src/ircprotocol.c index b16c2a6f..6816bf77 100644 --- a/src/ircprotocol.c +++ b/src/ircprotocol.c @@ -332,6 +332,11 @@ int InitIrcd( void ) return NS_SUCCESS; } +int FiniIrcd ( void ) { + ns_dlclose(protocol_module_handle); + return NS_SUCCESS; +} + /** @brief HaveFeature * * @return 1 if have else 0 diff --git a/src/main.c b/src/main.c index 35e6b84c..f60840a7 100644 --- a/src/main.c +++ b/src/main.c @@ -269,9 +269,11 @@ void FiniCore( void ) FiniBans(); FiniDns(); FiniModules(); - FiniSocks(); + FiniServices(); FiniBots(); FiniTimers(); + FiniSocks(); + FiniIrcd(); } /** @brief InitCore diff --git a/src/nsdba.c b/src/nsdba.c index 4bb82912..29239f13 100644 --- a/src/nsdba.c +++ b/src/nsdba.c @@ -65,6 +65,7 @@ static dbm_sym dbm_sym_table[] = static hash_t *dbhash; static char dbname[MAXPATH]; +void *dbm_module_handle; /** @brief InitDBAMSymbols * @@ -78,7 +79,6 @@ static char dbname[MAXPATH]; static int InitDBAMSymbols( void ) { static char dbm_path[MAXPATH]; - void *dbm_module_handle; dbm_sym *pdbm_sym; ircsnprintf( dbm_path, 255, "%s/%s%s", MOD_PATH, me.dbm, MOD_STDEXT ); @@ -157,6 +157,8 @@ void FiniDBA( void ) ns_free( dbe ); } hash_destroy( dbhash ); + ns_dlclose(dbm_module_handle); + } /** @brief DBAOpenDatabase @@ -204,7 +206,7 @@ int DBACloseDatabase( void ) hash_scan_begin( &ts, dbe->tablehash ); while(( tnode = hash_scan_next( &ts ) ) != NULL ) { tbe = (tableentry *) hnode_get( tnode ); - DBACloseTable( tbe->table ); + DBMCloseTable( tbe->handle ); hash_delete( dbe->tablehash, tnode ); hnode_destroy( tnode ); ns_free( tbe ); diff --git a/src/services.c b/src/services.c index 6cba4508..1bdcb644 100644 --- a/src/services.c +++ b/src/services.c @@ -200,7 +200,7 @@ void InitServices( void ) */ void FiniServices( void ) { - del_services_set_list (ns_debugsettings); + free(GET_CUR_MODULE()->event_list); } /** @brief init_services_bot diff --git a/src/signals.c b/src/signals.c index 7c910594..5440fadf 100644 --- a/src/signals.c +++ b/src/signals.c @@ -49,14 +49,10 @@ static char msg_sigterm[] = "SIGTERM received, shutting down server."; RETSIGTYPE sigterm_handler( int signum ) { -#ifdef VALGRIND - exit( NS_SUCCESS ); -#else /* VALGRIND */ nlog( LOG_CRITICAL, msg_sigterm ); /* XXX-Mark something is wrong with irc_globops */ irc_globops( NULL, msg_sigterm ); do_exit( NS_EXIT_NORMAL, msg_sigterm ); -#endif /* VALGRIND */ } /** @brief SIGHUP handler diff --git a/src/sock.c b/src/sock.c index 3d97df4c..a079658a 100644 --- a/src/sock.c +++ b/src/sock.c @@ -514,6 +514,7 @@ void FiniSocks (void) me.servsock = NULL; } hash_destroy(sockethash); + event_fini(); } /** @brief create a new socket diff --git a/src/transfer.c b/src/transfer.c index bc5f6a76..78882066 100644 --- a/src/transfer.c +++ b/src/transfer.c @@ -59,6 +59,7 @@ int InitCurl(void) void FiniCurl(void) { + curl_multi_cleanup(curlmultihandle); list_destroy_auto (activetransfers); } diff --git a/tools/neostats.suppression b/tools/neostats.suppression new file mode 100644 index 00000000..b7e2870b --- /dev/null +++ b/tools/neostats.suppression @@ -0,0 +1,99 @@ +{ + inet_ntoa + Memcheck:Leak + fun:malloc + fun:inet_ntoa +} + +{ + ns_dlopen + Memcheck:Leak + fun:calloc + fun:_dlerror_run + fun:dlopen@@GLIBC_2.1 + fun:ns_dlopen +} + +{ + ns_dlopen2 + Memcheck:Leak + fun:calloc + fun:_dl_new_object + fun:_dl_map_object_from_fd + fun:_dl_map_object + fun:dl_open_worker + fun:_dl_catch_error + fun:_dl_open + fun:dlopen_doit + fun:_dl_catch_error + fun:_dlerror_run + fun:dlopen@@GLIBC_2.1 + fun:ns_dlopen +} + +{ + ns_dlopen3 + Memcheck:Leak + fun:malloc + fun:realloc + fun:_dl_new_object + fun:_dl_map_object_from_fd + fun:_dl_map_object + fun:dl_open_worker + fun:_dl_catch_error + fun:_dl_open + fun:dlopen_doit + fun:_dl_catch_error + fun:_dlerror_run + fun:dlopen@@GLIBC_2.1 +} +{ + ns_dlopen4 + Memcheck:Leak + fun:calloc + fun:_dl_check_map_versions + fun:dl_open_worker + fun:_dl_catch_error + fun:_dl_open + fun:dlopen_doit + fun:_dl_catch_error + fun:_dlerror_run + fun:dlopen@@GLIBC_2.1 + fun:ns_dlopen + fun:InitDBAMSymbols + fun:InitDBA +} + +{ + ns_dlopen5 + Memcheck:Leak + fun:malloc + fun:_dl_map_object_deps + fun:dl_open_worker + fun:_dl_catch_error + fun:_dl_open + fun:dlopen_doit + fun:_dl_catch_error + fun:_dlerror_run + fun:dlopen@@GLIBC_2.1 + fun:ns_dlopen + fun:InitDBAMSymbols + fun:InitDBA +} + +{ + ns_dlopen6 + Memcheck:Leak + fun:malloc + fun:_dl_map_object + fun:dl_open_worker + fun:_dl_catch_error + fun:_dl_open + fun:dlopen_doit + fun:_dl_catch_error + fun:_dlerror_run + fun:dlopen@@GLIBC_2.1 + fun:ns_dlopen + fun:InitDBAMSymbols + fun:InitDBA +}