aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 6d6b9c9c..6fae7e41 100644
--- a/src/main.c
+++ b/src/main.c
@@ -579,7 +579,11 @@ int main(int argc, char *argv[]) {
/* Initialize the libev event loop. This needs to be done before loading
* the config file because the parser will install an ev_child watcher
- * for the nagbar when config errors are found. */
+ * for the nagbar when config errors are found.
+ *
+ * Main loop must be ev's default loop because (at the moment of writing)
+ * only the default loop can handle ev_child events and reap zombies
+ * (the start_application routine relies on that too). */
main_loop = EV_DEFAULT;
if (main_loop == NULL)
die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
@@ -1002,10 +1006,11 @@ int main(int argc, char *argv[]) {
char *log_stream_socket_path = get_process_filename("log-stream-socket");
int log_socket = create_socket(log_stream_socket_path, &current_log_stream_socket_path);
free(log_stream_socket_path);
+ struct ev_io *log_io = NULL;
if (log_socket == -1) {
ELOG("Could not create the log socket, i3-dump-log -f will not work\n");
} else {
- struct ev_io *log_io = scalloc(1, sizeof(struct ev_io));
+ log_io = scalloc(1, sizeof(struct ev_io));
ev_io_init(log_io, log_new_client, log_socket, EV_READ);
ev_io_start(main_loop, log_io);
}
@@ -1013,12 +1018,13 @@ int main(int argc, char *argv[]) {
/* Also handle the UNIX domain sockets passed via socket
* activation. The parameter 0 means "do not remove the
* environment variables", we need to be able to reexec. */
+ struct ev_io *socket_ipc_io = NULL;
listen_fds = sd_listen_fds(0);
- if (listen_fds < 0)
+ if (listen_fds < 0) {
ELOG("socket activation: Error in sd_listen_fds\n");
- else if (listen_fds == 0)
+ } else if (listen_fds == 0) {
DLOG("socket activation: no sockets passed\n");
- else {
+ } else {
int flags;
for (int fd = SD_LISTEN_FDS_START;
fd < (SD_LISTEN_FDS_START + listen_fds);
@@ -1033,9 +1039,9 @@ int main(int argc, char *argv[]) {
ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd);
}
- struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
- ev_io_init(ipc_io, ipc_new_client, fd, EV_READ);
- ev_io_start(main_loop, ipc_io);
+ socket_ipc_io = scalloc(1, sizeof(struct ev_io));
+ ev_io_init(socket_ipc_io, ipc_new_client, fd, EV_READ);
+ ev_io_start(main_loop, socket_ipc_io);
}
}
@@ -1198,4 +1204,10 @@ int main(int argc, char *argv[]) {
sd_notify(1, "READY=1");
ev_loop(main_loop, 0);
+
+ /* Free these heap allocations just to satisfy LeakSanitizer. */
+ FREE(ipc_io);
+ FREE(socket_ipc_io);
+ FREE(log_io);
+ FREE(xcb_watcher);
}