This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix [BZ#14122] memory leak in nss_parse_service_list


Greetings,

Here is a rather simple fix for [BZ#14122]: memory leak in
nss_parse_service_list.

Tested on Linux/x86_64 and i686.

--


2012-05-20  Paul Pluzhnikov  <ppluzhnikov@google.com>

	[BZ #14122]
	* nss/nsswitch.c (nss_parse_service_list): Don't leak memory on
	error paths.


diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 53ff5f8..144acb1 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -644,7 +644,7 @@ nss_parse_service_list (const char *line)
 		  else if (__strncasecmp (name, "UNAVAIL", 7) == 0)
 		    status = NSS_STATUS_UNAVAIL;
 		  else
-		    return result;
+		    goto finish;
 		}
 	      else if (line - name == 8)
 		{
@@ -653,15 +653,15 @@ nss_parse_service_list (const char *line)
 		  else if (__strncasecmp (name, "TRYAGAIN", 8) == 0)
 		    status = NSS_STATUS_TRYAGAIN;
 		  else
-		    return result;
+		    goto finish;
 		}
 	      else
-		return result;
+		goto finish;
 
 	      while (isspace (line[0]))
 		++line;
 	      if (line[0] != '=')
-		return result;
+		goto finish;
 	      do
 		++line;
 	      while (isspace (line[0]));
@@ -677,7 +677,7 @@ nss_parse_service_list (const char *line)
 		       && __strncasecmp (name, "CONTINUE", 8) == 0)
 		action = NSS_ACTION_CONTINUE;
 	      else
-		return result;
+		goto finish;
 
 	      if (not)
 		{
@@ -705,6 +705,11 @@ nss_parse_service_list (const char *line)
 
       *nextp = new_service;
       nextp = &new_service->next;
+      continue;
+
+    finish:
+      free (new_service);
+      return result;
     }
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]