From 83af542d501fb54f5db598e5799c5b5aacbd4bb3 Mon Sep 17 00:00:00 2001 From: antma Date: Fri, 10 Jan 2014 15:40:28 +0400 Subject: [PATCH] close /etc/passwd file handle right after evaluating home directory --- main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 4c6841f..e57da3b 100644 --- a/main.c +++ b/main.c @@ -120,16 +120,25 @@ void set_terminal_attributes (void) { /* }}} */ char *get_home_directory (void) { + static char *home_directory = NULL; + if (home_directory != NULL) { + return home_directory; + } struct passwd *current_passwd; uid_t user_id; setpwent (); user_id = getuid (); while ((current_passwd = getpwent ())) { if (current_passwd->pw_uid == user_id) { - return current_passwd->pw_dir; + home_directory = tstrdup (current_passwd->pw_dir); + break; } } - return ""; + endpwent (); + if (home_directory == NULL) { + home_directory = tstrdup ("."); + } + return home_directory; } char *get_config_directory (void) {