From ee1952424d8e936ac79e534d88c2452f34136e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Fran=C3=A7ois?= Date: Fri, 2 Aug 2013 20:28:24 +0200 Subject: [PATCH] Fix memory leak. * libmisc/setupenv.c: Free pw_dir and pw_shell before reallocating them. --- ChangeLog | 2 ++ libmisc/setupenv.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index b7a1e142..f5a86486 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * libmisc/setupenv.c: xstrdup the static char* temp_pw_dir / temp_pw_shell. That way we can continue to use pw_free() without segving. Thanks to Serge Hallyn for the patch. + * libmisc/setupenv.c: Free pw_dir and pw_shell before reallocating + them. 2013-08-01 Yuri Kozlov diff --git a/libmisc/setupenv.c b/libmisc/setupenv.c index 28891ae1..8020f3d5 100644 --- a/libmisc/setupenv.c +++ b/libmisc/setupenv.c @@ -228,6 +228,7 @@ void setup_env (struct passwd *info) exit (EXIT_FAILURE); } (void) puts (_("No directory, logging in with HOME=/")); + free (info->pw_dir); info->pw_dir = xstrdup (temp_pw_dir); } @@ -244,6 +245,7 @@ void setup_env (struct passwd *info) if ((NULL == info->pw_shell) || ('\0' == *info->pw_shell)) { static char temp_pw_shell[] = SHELL; + free (info->pw_shell); info->pw_shell = xstrdup (temp_pw_shell); }