Make some essentially cosmetic changes to return memory when the program exits. The program never exits, but it's good for valgrind.

This commit is contained in:
Mike Brady
2018-05-11 10:56:16 +01:00
parent c43e1d7be7
commit d805ce914e
3 changed files with 44 additions and 20 deletions
+10 -2
View File
@@ -364,9 +364,17 @@ static int avahi_register(char *srvname, int srvport) {
static void avahi_unregister(void) {
debug(1, "avahi: avahi_unregister.");
if (tpoll)
if (tpoll) {
avahi_threaded_poll_stop(tpoll);
tpoll = NULL;
if (client) {
avahi_client_free(client);
client = NULL;
};
avahi_threaded_poll_free(tpoll);
tpoll = NULL;
}
if (service_name)
free(service_name);
+12 -5
View File
@@ -2082,14 +2082,15 @@ void rtsp_listen_loop(void) {
}
mdns_register();
// printf("Listening for connections.");
// shairport_startup_complete();
int acceptfd;
struct timeval tv;
while (1) {
tv.tv_sec = 300;
do {
tv.tv_sec = 60;
tv.tv_usec = 0;
for (i = 0; i < nsock; i++)
@@ -2182,7 +2183,13 @@ void rtsp_listen_loop(void) {
conn->running = 1; // this must happen before the thread is tracked
track_thread(conn);
}
}
perror("select");
die("fell out of the RTSP select loop");
} while (1);
mdns_unregister();
if (sockfd)
free(sockfd);
//perror("select");
//die("fell out of the RTSP select loop");
}
+22 -13
View File
@@ -274,6 +274,8 @@ int parse_options(int argc, char **argv) {
optind = j;
optCon = poptGetContext(NULL, optind, (const char **)argv, optionsTable, 0);
if (optCon==NULL)
die("Can not get a secondary popt context.");
poptSetOtherOptionHelp(optCon, "[OPTIONS]* ");
/* Now do options processing just to get a debug level */
@@ -318,6 +320,8 @@ int parse_options(int argc, char **argv) {
die("%s: %s", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
}
poptFreeContext(optCon);
if ((daemonisewith) && (daemonisewithout))
die("Select either daemonize_with_pid_file or daemonize_without_pid_file -- you have selected "
"both!");
@@ -888,6 +892,8 @@ int parse_options(int argc, char **argv) {
optind = j;
optCon = poptGetContext(NULL, optind, (const char **)argv, optionsTable, 0);
if (optCon==NULL)
die("Can not get a popt context.");
poptSetOtherOptionHelp(optCon, "[OPTIONS]* ");
/* Now do options processing, get portname */
@@ -935,6 +941,7 @@ int parse_options(int argc, char **argv) {
die("%s: %s", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
}
poptFreeContext(optCon);
#ifdef CONFIG_METADATA
if ((config.metadata_enabled == 1) && (config.metadata_pipename == NULL))
config.metadata_pipename = strdup("/tmp/shairport-sync-metadata");
@@ -956,6 +963,10 @@ int parse_options(int argc, char **argv) {
char hostname[100];
gethostname(hostname, 100);
char *i1 = str_replace(raw_service_name, "%h", hostname);
if (raw_service_name) {
free(raw_service_name);
raw_service_name = NULL;
}
if ((hostname[0] >= 'a') && (hostname[0] <= 'z'))
hostname[0] = hostname[0] - 0x20; // convert a lowercase first letter into a capital letter
char *i2 = str_replace(i1, "%H", hostname);
@@ -1041,13 +1052,15 @@ void shairport_startup_complete(void) {
}
}
const char *pid_file_proc(void) {
char fn[8192];
snprintf(fn, sizeof(fn), "%s/%s.pid", config.computed_piddir,
daemon_pid_file_ident ? daemon_pid_file_ident : "unknown");
// debug(1,"fn \"%s\".",fn);
return strdup(fn);
const char *pid_file_proc(char* fn,size_t max_length) {
if (fn) {
snprintf(fn, max_length, "%s/%s.pid", config.computed_piddir,
daemon_pid_file_ident ? daemon_pid_file_ident : "unknown");
// debug(1,"fn \"%s\".",fn);
} else {
debug(1,"the sise of the buffer for the PID file path is zero.");
}
return fn;
}
void exit_function() {
@@ -1168,11 +1181,6 @@ int main(int argc, char **argv) {
return 1;
}
// Point to a function to help locate where the PID file will go
// We always use this function because the default location
// is unsatisfactory. By default we want to use /var/run/shairport-sync/.
daemon_pid_file_proc = pid_file_proc;
/* Set indentification string for the daemon for both syslog and PID file */
daemon_pid_file_ident = daemon_log_ident = daemon_ident_from_argv0(argv[0]);
@@ -1366,10 +1374,11 @@ int main(int argc, char **argv) {
debug(1, "Can't print the version information!");
}
char pid_file_path_string[4096] = "\0";
/* Print out options */
debug(1, "statistics_requester status is %d.", config.statistics_requested);
debug(1, "daemon status is %d.", config.daemonise);
debug(1, "deamon pid file is \"%s\".", pid_file_proc());
debug(1, "deamon pid file is \"%s\".", pid_file_proc(pid_file_path_string,4096));
debug(1, "rtsp listening port is %d.", config.port);
debug(1, "udp base port is %d.", config.udp_port_base);
debug(1, "udp port range is %d.", config.udp_port_range);