Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memleak hunting: cleanup based on valgrind report #1649

Merged
merged 7 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 8 additions & 46 deletions contrib/valgrind/syslog-ng.supp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
}

## Miscellaneous non-leaks and false alarms
{
suppress_journald_open: see https://github.com/systemd/systemd/issues/6539
Memcheck:Leak
...
fun:journald_open
...
}

{
suppress_syslog_ng_set_argv_space
Memcheck:Leak
Expand Down Expand Up @@ -50,17 +58,6 @@
fun:main
}

{
suppress_syslog_ng_path_resolver
Memcheck:Leak
fun:*alloc
...
fun:path_resolver_new
...
fun:main_loop_global_init
fun:main
}

{
suppress_syslog_ng_option_context_parse
Memcheck:Leak
Expand Down Expand Up @@ -104,15 +101,6 @@
fun:clone
}

{
suppress_syslog_ng_reloc
Memcheck:Leak
fun:*alloc
...
fun:cache_*
fun:get_installation_path_for
}

{
suppress_syslog_ng_msg_limit_internal_message
Memcheck:Leak
Expand All @@ -132,14 +120,6 @@
fun:main_loop_run
}

{
suppress_syslog_ng_aftiner_message_posted
Memcheck:Leak
fun:*alloc
...
fun:afinter_message_posted
}

{
supperess_syslog_ng_log_msg_new_internal
Memcheck:Leak
Expand Down Expand Up @@ -189,15 +169,6 @@
fun:BIO_*
}

{
suppress_crypto_ERR_leaks
Memcheck:Leak
fun:*alloc
...
obj:*/libcrypto.so.*
fun:ERR_*
}

{
suppress_crypto_OCSP_leaks
Memcheck:Leak
Expand All @@ -207,15 +178,6 @@
fun:OCSP_*
}

{
suppress_crypto_EVP_leaks
Memcheck:Leak
fun:*alloc
...
obj:*/libcrypto.so.*
fun:EVP_*
}

## TLS/SSL related syslog-ng leaks
{
suppress_syslog_ng_crypto_leaks
Expand Down
16 changes: 16 additions & 0 deletions lib/afinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,19 @@ afinter_global_init(void)
{
register_application_hook(AH_POST_CONFIG_LOADED, afinter_register_posted_hook, NULL);
}

void
afinter_global_deinit(void)
{
if (internal_msg_queue)
{
stats_lock();
StatsClusterKey sc_key;
stats_cluster_logpipe_key_set(&sc_key, SCS_GLOBAL, "internal_queue_length", NULL );
stats_unregister_counter(&sc_key, SC_TYPE_PROCESSED, &internal_queue_length);
stats_unlock();
g_queue_free_full(internal_msg_queue, (GDestroyNotify)log_msg_unref);
internal_msg_queue = NULL;
}
current_internal_source = NULL;
}
1 change: 1 addition & 0 deletions lib/afinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ typedef struct _AFInterSourceDriver
void afinter_postpone_mark(gint mark_freq);
LogDriver *afinter_sd_new(GlobalConfig *cfg);
void afinter_global_init(void);
void afinter_global_deinit(void);

#endif
1 change: 1 addition & 0 deletions lib/apphook.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ app_shutdown(void)
log_tags_global_deinit();
log_msg_global_deinit();

afinter_global_deinit();
stats_destroy();
child_manager_deinit();
g_list_foreach(application_hooks, (GFunc) g_free, NULL);
Expand Down
13 changes: 13 additions & 0 deletions lib/control/control-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@

static GList *command_list = NULL;

GList *
get_control_command_list()
{
return command_list;
}

void
reset_control_command_list()
{
g_list_free_full(command_list, (GDestroyNotify)g_free);
command_list = NULL;
}

void
control_register_command(const gchar *command_name, const gchar *description, CommandFunction function,
gpointer user_data)
Expand Down
2 changes: 2 additions & 0 deletions lib/control/control-commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@

void control_register_command(const gchar *command_name, const gchar *description, CommandFunction function, gpointer user_data);
GList *control_register_default_commands(MainLoop *main_loop);
GList *get_control_command_list();
void reset_control_command_list();

#endif
8 changes: 7 additions & 1 deletion lib/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/evp.h>

#include <stdio.h>

static gboolean randfile_loaded;
Expand All @@ -48,6 +51,10 @@ crypto_deinit(void)
if (rnd_file[0])
RAND_write_file(rnd_file);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
ERR_free_strings();
EVP_cleanup();
#endif
openssl_crypto_deinit_threading();
}

Expand All @@ -73,4 +80,3 @@ crypto_init(void)
"WARNING: a trusted random number source is not available, crypto operations will probably fail. Please set the RANDFILE environment variable.");
}
}

19 changes: 17 additions & 2 deletions lib/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ msg_post_message(LogMessage *msg)
log_msg_unref(msg);
}

static guint g_log_handler_id;
static guint glib_handler_id;

void
msg_init(gboolean interactive)
{
Expand All @@ -269,8 +272,8 @@ msg_init(gboolean interactive)

if (!interactive)
{
g_log_set_handler(G_LOG_DOMAIN, 0xff, msg_log_func, NULL);
g_log_set_handler("GLib", 0xff, msg_log_func, NULL);
g_log_handler_id = g_log_set_handler(G_LOG_DOMAIN, 0xff, msg_log_func, NULL);
glib_handler_id = g_log_set_handler("GLib", 0xff, msg_log_func, NULL);
}
else
{
Expand All @@ -285,7 +288,19 @@ void
msg_deinit(void)
{
evt_ctx_free(evt_context);
evt_context = NULL;
log_stderr = TRUE;

if (g_log_handler_id)
{
g_log_remove_handler(G_LOG_DOMAIN, g_log_handler_id);
g_log_handler_id = 0;
}
if (glib_handler_id)
{
g_log_remove_handler("GLib", glib_handler_id);
glib_handler_id = 0;
}
}

static GOptionEntry msg_option_entries[] =
Expand Down
10 changes: 10 additions & 0 deletions lib/reloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,13 @@ get_installation_path_for(const gchar *template)
path_cache = cache_new(path_resolver_new(lookup_sysprefix()));
return cache_lookup(path_cache, template);
}

void
reloc_deinit(void)
{
if (path_cache)
{
cache_free(path_cache);
path_cache = NULL;
}
}
1 change: 1 addition & 0 deletions lib/reloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ void path_resolver_add_configure_variable(CacheResolver *self, const gchar *name
CacheResolver *path_resolver_new(const gchar *sysprefix);

const gchar *get_installation_path_for(const gchar *template);
void reloc_deinit(void);

#endif
6 changes: 6 additions & 0 deletions lib/stats/stats-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ stats_register_control_commands(void)
control_register_command("STATS", NULL, control_connection_send_stats, NULL);
control_register_command("RESET_STATS", NULL, control_connection_reset_stats, NULL);
}

void
stats_unregister_control_commands(void)
{
reset_control_command_list();
}
1 change: 1 addition & 0 deletions lib/stats/stats-control.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
#include "syslog-ng.h"

void stats_register_control_commands(void);
void stats_unregister_control_commands(void);

#endif
1 change: 1 addition & 0 deletions lib/stats/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ stats_destroy(void)
{
stats_query_deinit();
stats_registry_deinit();
stats_unregister_control_commands();
}

void
Expand Down
1 change: 1 addition & 0 deletions lib/value-pairs/value-pairs.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,4 +986,5 @@ value_pairs_global_init(void)
void
value_pairs_global_deinit(void)
{
g_free(all_macros);
}
2 changes: 1 addition & 1 deletion syslog-ng/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,6 @@ main(int argc, char *argv[])
app_shutdown();
z_mem_trace_dump();
g_process_finish();
reloc_deinit();
return rc;
}