diff mbox series

nscd: Deallocate existing user names in file parser

Message ID 20180813130137.87407403D3739@oldenburg.str.redhat.com
State New
Headers show
Series nscd: Deallocate existing user names in file parser | expand

Commit Message

Florian Weimer Aug. 13, 2018, 1:01 p.m. UTC
This avoids a theoretical memory leak (theoretical because it depends on
multiple server-user/stat-user directives in the configuration file).

2018-08-13  Florian Weimer  <fweimer@redhat.com>

	* nscd/nscd_conf.c (nscd_parse_file): Deallocate old storage for
	server_user, stat_user.
diff mbox series

Patch

diff --git a/nscd/nscd_conf.c b/nscd/nscd_conf.c
index 265a02434d..7293b795b6 100644
--- a/nscd/nscd_conf.c
+++ b/nscd/nscd_conf.c
@@ -190,7 +190,10 @@  nscd_parse_file (const char *fname, struct database_dyn dbs[lastdb])
 	  if (!arg1)
 	    error (0, 0, _("Must specify user name for server-user option"));
 	  else
-	    server_user = xstrdup (arg1);
+	    {
+	      free ((char *) server_user);
+	      server_user = xstrdup (arg1);
+	    }
 	}
       else if (strcmp (entry, "stat-user") == 0)
 	{
@@ -198,6 +201,7 @@  nscd_parse_file (const char *fname, struct database_dyn dbs[lastdb])
 	    error (0, 0, _("Must specify user name for stat-user option"));
 	  else
 	    {
+	      free ((char *) stat_user);
 	      stat_user = xstrdup (arg1);
 
 	      struct passwd *pw = getpwnam (stat_user);