diff --git a/awesome-client-common.c b/awesome-client-common.c index 0086e803..7c843746 100644 --- a/awesome-client-common.c +++ b/awesome-client-common.c @@ -31,7 +31,7 @@ struct sockaddr_un * get_client_addr(const char *display) { - char *homedir; + char *homedir, *tmp; ssize_t path_len; struct sockaddr_un *addr; @@ -39,6 +39,8 @@ get_client_addr(const char *display) homedir = getenv("HOME"); /* (a_strlen(display) - 1) because we strcat on display + 1 and * + 3 for /, \0 and possibly 0 if display is NULL */ + if(display && (tmp = strrchr(display, '.'))) + *tmp = '\0'; path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + (a_strlen(display) - 1) + 3; if(path_len >= ssizeof(addr->sun_path)) { diff --git a/awesome-client.c b/awesome-client.c index 9fa1a616..5a3c019c 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -38,14 +38,11 @@ int main(void) { struct sockaddr_un *addr; - char buf[1024], *display, *tmp; + char buf[1024]; int csfd, ret_value = EXIT_SUCCESS; csfd = get_client_socket(); - display = a_strdup(getenv("DISPLAY")); - if(display && (tmp = strrchr(display, '.'))) - *tmp = '\0'; - addr = get_client_addr(display); + addr = get_client_addr(getenv("DISPLAY")); if(!addr || csfd < 0) return EXIT_FAILURE; @@ -69,7 +66,6 @@ main(void) close(csfd); p_delete(&addr); - p_delete(&display); return ret_value; }