Fix small leak in i3bar's main

If -s is used, the socket_path returned by getenv is never freed.

Also some small rearrangements.
This commit is contained in:
Orestis Floros 2019-10-14 03:54:05 +03:00
parent 5f54971425
commit ee30c34b5c
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
1 changed files with 14 additions and 10 deletions

View File

@ -92,13 +92,7 @@ static void sig_cb(struct ev_loop *loop, ev_signal *watcher, int revents) {
}
int main(int argc, char **argv) {
int opt;
int option_index = 0;
char *socket_path = getenv("I3SOCK");
if (socket_path != NULL) {
socket_path = sstrdup(socket_path);
}
char *i3_default_sock_path = "/tmp/i3-ipc.sock";
char *socket_path = NULL;
/* Initialize the standard config to use 0 as default */
memset(&config, '\0', sizeof(config_t));
@ -112,6 +106,8 @@ int main(int argc, char **argv) {
{"verbose", no_argument, 0, 'V'},
{NULL, 0, 0, 0}};
int opt;
int option_index = 0;
while ((opt = getopt_long(argc, argv, "b:s:thvV", long_opt, &option_index)) != -1) {
switch (opt) {
case 's':
@ -144,10 +140,17 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
main_loop = ev_default_loop(0);
main_loop = ev_default_loop(0); /* needed in init_xcb_early */
char *atom_sock_path = init_xcb_early();
/* Select a socket_path if the user hasn't specified one */
if (socket_path == NULL) {
socket_path = getenv("I3SOCK");
if (socket_path != NULL) {
socket_path = sstrdup(socket_path);
}
}
if (socket_path == NULL) {
socket_path = atom_sock_path;
} else {
@ -155,8 +158,9 @@ int main(int argc, char **argv) {
}
if (socket_path == NULL) {
char *i3_default_sock_path = "/tmp/i3-ipc.sock";
ELOG("No socket path specified, default to %s\n", i3_default_sock_path);
socket_path = expand_path(i3_default_sock_path);
socket_path = sstrdup(i3_default_sock_path);
}
init_dpi();