Some modification of initialization.

home_dir variable intialization is moved from main() to OS_setup().
Fixed memory leak ('shell' variable).
This commit is contained in:
Andrew Borodin 2009-06-30 21:49:40 +04:00
parent 7de080e123
commit 6b07af2fc4

View File

@ -1896,25 +1896,39 @@ do_nc (void)
static void static void
OS_Setup (void) OS_Setup (void)
{ {
const char *shell_env = getenv ("SHELL");
const char *mc_libdir; const char *mc_libdir;
shell = getenv ("SHELL");
if (!shell || !*shell) { if ((shell_env == NULL) || (shell_env[0] == '\0')) {
struct passwd *pwd; struct passwd *pwd;
pwd = getpwuid (geteuid ()); pwd = getpwuid (geteuid ());
if (pwd != NULL) if (pwd != NULL)
shell = g_strdup (pwd->pw_shell); shell = g_strdup (pwd->pw_shell);
} else
shell = g_strdup (shell_env);
if ((shell == NULL) || (shell[0] == '\0')) {
g_free (shell);
shell = g_strdup ("/bin/sh");
} }
if (!shell || !*shell)
shell = "/bin/sh";
/* This is the directory, where MC was installed, on Unix this is DATADIR */ /* This is the directory, where MC was installed, on Unix this is DATADIR */
/* and can be overriden by the MC_DATADIR environment variable */ /* and can be overriden by the MC_DATADIR environment variable */
if ((mc_libdir = getenv ("MC_DATADIR")) != NULL) { mc_libdir = getenv ("MC_DATADIR");
if (mc_libdir != NULL) {
mc_home = g_strdup (mc_libdir); mc_home = g_strdup (mc_libdir);
mc_home_alt = g_strdup (SYSCONFDIR);
} else { } else {
mc_home = g_strdup (SYSCONFDIR); mc_home = g_strdup (SYSCONFDIR);
mc_home_alt = g_strdup (DATADIR);
} }
mc_home_alt = mc_libdir != NULL ? g_strdup (SYSCONFDIR) : g_strdup (DATADIR);
/* This variable is used by the subshell */
home_dir = getenv ("HOME");
if (!home_dir)
home_dir = mc_home;
} }
static void static void
@ -2270,13 +2284,6 @@ main (int argc, char *argv[])
OS_Setup (); OS_Setup ();
/* This variable is used by the subshell */
home_dir = getenv ("HOME");
if (!home_dir) {
/* mc_home was computed by OS_Setup */
home_dir = mc_home;
}
str_init_strings (NULL); str_init_strings (NULL);
vfs_init (); vfs_init ();
@ -2404,6 +2411,8 @@ main (int argc, char *argv[])
g_free (mc_home_alt); g_free (mc_home_alt);
g_free (mc_home); g_free (mc_home);
g_free (shell);
done_key (); done_key ();
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
free_codepages_list (); free_codepages_list ();