[-] Free events on exit (turns out event_base_free does not free them)

Credit @whatdoineed2do, ref. pr #797
This commit is contained in:
ejurgensen 2019-09-09 22:21:23 +02:00
parent 0a593463b8
commit 4ab734343c
11 changed files with 45 additions and 32 deletions

View File

@ -1673,6 +1673,7 @@ cache_deinit(void)
return; return;
} }
// Free event base (should free events too) // Free event base
event_free(cache_daap_updateev);
event_base_free(evbase_cache); event_base_free(evbase_cache);
} }

View File

@ -166,6 +166,22 @@ send_command(struct commands_base *cmdbase, struct command *cmd)
return 0; return 0;
} }
/*
* Frees the command base and closes the (internally used) pipes
*/
int
commands_base_free(struct commands_base *cmdbase)
{
if (cmdbase->command_event)
event_free(cmdbase->command_event);
close(cmdbase->command_pipe[0]);
close(cmdbase->command_pipe[1]);
free(cmdbase);
return 0;
}
/* /*
* Creates a new command base, needs to be freed by commands_base_destroy or commands_base_free. * Creates a new command base, needs to be freed by commands_base_destroy or commands_base_free.
* *
@ -178,12 +194,7 @@ commands_base_new(struct event_base *evbase, command_exit_cb exit_cb)
struct commands_base *cmdbase; struct commands_base *cmdbase;
int ret; int ret;
cmdbase = calloc(1, sizeof(struct commands_base)); CHECK_NULL(L_MAIN, cmdbase = calloc(1, sizeof(struct commands_base)));
if (!cmdbase)
{
DPRINTF(E_LOG, L_MAIN, "Out of memory for cmdbase\n");
return NULL;
}
#ifdef HAVE_PIPE2 #ifdef HAVE_PIPE2
ret = pipe2(cmdbase->command_pipe, O_CLOEXEC); ret = pipe2(cmdbase->command_pipe, O_CLOEXEC);
@ -201,9 +212,7 @@ commands_base_new(struct event_base *evbase, command_exit_cb exit_cb)
if (!cmdbase->command_event) if (!cmdbase->command_event)
{ {
DPRINTF(E_LOG, L_MAIN, "Could not create cmd event\n"); DPRINTF(E_LOG, L_MAIN, "Could not create cmd event\n");
close(cmdbase->command_pipe[0]); commands_base_free(cmdbase);
close(cmdbase->command_pipe[1]);
free(cmdbase);
return NULL; return NULL;
} }
@ -211,9 +220,7 @@ commands_base_new(struct event_base *evbase, command_exit_cb exit_cb)
if (ret != 0) if (ret != 0)
{ {
DPRINTF(E_LOG, L_MAIN, "Could not add cmd event\n"); DPRINTF(E_LOG, L_MAIN, "Could not add cmd event\n");
close(cmdbase->command_pipe[0]); commands_base_free(cmdbase);
close(cmdbase->command_pipe[1]);
free(cmdbase);
return NULL; return NULL;
} }
@ -223,20 +230,6 @@ commands_base_new(struct event_base *evbase, command_exit_cb exit_cb)
return cmdbase; return cmdbase;
} }
/*
* Frees the command base and closes the (internally used) pipes
*/
int
commands_base_free(struct commands_base *cmdbase)
{
event_free(cmdbase->command_event);
close(cmdbase->command_pipe[0]);
close(cmdbase->command_pipe[1]);
free(cmdbase);
return 0;
}
/* /*
* Gets the current return value for the current pending command. * Gets the current return value for the current pending command.
* *

View File

@ -1748,7 +1748,7 @@ httpd_init(const char *webroot)
{ {
DPRINTF(E_FATAL, L_HTTPD, "Could not create exit event\n"); DPRINTF(E_FATAL, L_HTTPD, "Could not create exit event\n");
goto event_fail; goto exitev_fail;
} }
event_add(exitev, NULL); event_add(exitev, NULL);
@ -1757,7 +1757,7 @@ httpd_init(const char *webroot)
{ {
DPRINTF(E_FATAL, L_HTTPD, "Could not create HTTP server\n"); DPRINTF(E_FATAL, L_HTTPD, "Could not create HTTP server\n");
goto event_fail; goto evhttpd_fail;
} }
v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"); v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
@ -1819,7 +1819,9 @@ httpd_init(const char *webroot)
thread_fail: thread_fail:
bind_fail: bind_fail:
evhttp_free(evhttpd); evhttp_free(evhttpd);
event_fail: evhttpd_fail:
event_free(exitev);
exitev_fail:
#ifdef HAVE_EVENTFD #ifdef HAVE_EVENTFD
close(exit_efd); close(exit_efd);
#else #else
@ -1899,6 +1901,7 @@ httpd_deinit(void)
close(exit_pipe[0]); close(exit_pipe[0]);
close(exit_pipe[1]); close(exit_pipe[1]);
#endif #endif
event_free(exitev);
evhttp_free(evhttpd); evhttp_free(evhttpd);
event_base_free(evbase_httpd); event_base_free(evbase_httpd);
} }

View File

@ -686,6 +686,7 @@ streaming_deinit(void)
{ {
streaming_end(); streaming_end();
event_free(metaev);
event_free(streamingev); event_free(streamingev);
streamingev = NULL; streamingev = NULL;

View File

@ -935,6 +935,8 @@ input_init(void)
thread_fail: thread_fail:
commands_base_free(cmdbase); commands_base_free(cmdbase);
input_fail: input_fail:
event_free(input_open_timeout_ev);
event_free(input_ev);
evbuffer_free(input_buffer.evbuf); evbuffer_free(input_buffer.evbuf);
event_base_free(evbase_input); event_base_free(evbase_input);
return -1; return -1;
@ -971,6 +973,8 @@ input_deinit(void)
pthread_cond_destroy(&input_buffer.cond); pthread_cond_destroy(&input_buffer.cond);
pthread_mutex_destroy(&input_buffer.mutex); pthread_mutex_destroy(&input_buffer.mutex);
event_free(input_open_timeout_ev);
event_free(input_ev);
evbuffer_free(input_buffer.evbuf); evbuffer_free(input_buffer.evbuf);
event_base_free(evbase_input); event_base_free(evbase_input);
} }

View File

@ -791,5 +791,6 @@ library_deinit()
sources[i]->deinit(); sources[i]->deinit();
} }
event_free(updateev);
event_base_free(evbase_lib); event_base_free(evbase_lib);
} }

View File

@ -919,6 +919,8 @@ main(int argc, char **argv)
DPRINTF(E_LOG, L_MAIN, "Stopping gracefully\n"); DPRINTF(E_LOG, L_MAIN, "Stopping gracefully\n");
ret = EXIT_SUCCESS; ret = EXIT_SUCCESS;
event_free(sig_event);
/* /*
* On a clean shutdown, bring mDNS down first to give a chance * On a clean shutdown, bring mDNS down first to give a chance
* to the clients to perform a clean shutdown on their end * to the clients to perform a clean shutdown on their end
@ -971,6 +973,8 @@ main(int argc, char **argv)
} }
mdns_fail: mdns_fail:
event_base_free(evbase_main);
daemon_fail: daemon_fail:
if (background) if (background)
{ {

View File

@ -1043,7 +1043,7 @@ outputs_deinit(void)
{ {
int i; int i;
evtimer_del(outputs_deferredev); event_free(outputs_deferredev);
for (i = 0; outputs[i]; i++) for (i = 0; outputs[i]; i++)
{ {

View File

@ -3327,6 +3327,7 @@ player_init(void)
outputs_deinit(); outputs_deinit();
error_evbase_free: error_evbase_free:
commands_base_free(cmdbase); commands_base_free(cmdbase);
event_free(pb_timer_ev);
event_base_free(evbase_player); event_base_free(evbase_player);
#ifdef HAVE_TIMERFD #ifdef HAVE_TIMERFD
close(pb_timer_fd); close(pb_timer_fd);
@ -3369,5 +3370,6 @@ player_deinit(void)
free(history); free(history);
event_free(pb_timer_ev);
event_base_free(evbase_player); event_base_free(evbase_player);
} }

View File

@ -861,6 +861,8 @@ remote_pairing_deinit(void)
if (remote_info) if (remote_info)
free_remote(remote_info); free_remote(remote_info);
event_free(pairingev);
#ifdef HAVE_EVENTFD #ifdef HAVE_EVENTFD
close(pairing_efd); close(pairing_efd);
#else #else

View File

@ -1582,6 +1582,7 @@ spotify_init(void)
session_fail: session_fail:
cmd_fail: cmd_fail:
event_free(g_notifyev);
evnew_fail: evnew_fail:
commands_base_free(cmdbase); commands_base_free(cmdbase);
event_base_free(evbase_spotify); event_base_free(evbase_spotify);
@ -1625,7 +1626,8 @@ spotify_deinit(void)
/* Release session */ /* Release session */
fptr_sp_session_release(g_sess); fptr_sp_session_release(g_sess);
/* Free event base (should free events too) */ /* Free event base */
event_free(g_notifyev);
event_base_free(evbase_spotify); event_base_free(evbase_spotify);
/* Close pipes */ /* Close pipes */