[Pkg-shadow-commits] r3170 - in upstream/trunk: . lib

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Sat Mar 20 10:21:41 UTC 2010


Author: nekral-guest
Date: 2010-03-20 10:21:40 +0000 (Sat, 20 Mar 2010)
New Revision: 3170

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/lib/groupio.c
Log:
	* lib/groupio.c: Fix memory management insplit_groups().


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2010-03-20 10:19:50 UTC (rev 3169)
+++ upstream/trunk/ChangeLog	2010-03-20 10:21:40 UTC (rev 3170)
@@ -1,5 +1,9 @@
 2010-03-20  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* lib/groupio.c: Fix memory management insplit_groups().
+
+2010-03-20  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* libmisc/strtoday.c: Empty dates indicate a disabled date, this is
 	not an error.
 

Modified: upstream/trunk/lib/groupio.c
===================================================================
--- upstream/trunk/lib/groupio.c	2010-03-20 10:19:50 UTC (rev 3169)
+++ upstream/trunk/lib/groupio.c	2010-03-20 10:21:40 UTC (rev 3170)
@@ -382,6 +382,7 @@
 		struct commonio_entry *new;
 		struct group *new_gptr;
 		unsigned int members = 0;
+		int i;
 
 		/* Check if this group must be split */
 		if (!gr->changed)
@@ -408,9 +409,23 @@
 		new->changed = true;
 
 		/* Enforce the maximum number of members on gptr */
-		gptr->gr_mem[max_members] = NULL;
+		for (i = max_members; NULL != gptr->gr_mem[i]; i++) {
+			free (gptr->gr_mem[i]);
+			gptr->gr_mem[i] = NULL;
+		}
+		/* Shift all the members */
 		/* The number of members in new_gptr will be check later */
-		new_gptr->gr_mem = &new_gptr->gr_mem[max_members];
+		for (i = 0; NULL != new_gptr->gr_mem[i + max_members]; i++) {
+			if (NULL != new_gptr->gr_mem[i]) {
+				free (new_gptr->gr_mem[i]);
+			}
+			new_gptr->gr_mem[i] = new_gptr->gr_mem[i + max_members];
+			new_gptr->gr_mem[i + max_members] = NULL;
+		}
+		for (; NULL != new_gptr->gr_mem[i]; i++) {
+			free (new_gptr->gr_mem[i]);
+			new_gptr->gr_mem[i] = NULL;
+		}
 
 		/* insert the new entry in the list */
 		new->prev = gr;




More information about the Pkg-shadow-commits mailing list