* lib/groupio.c: Fix memory management insplit_groups().

This commit is contained in:
nekral-guest 2010-03-20 10:21:40 +00:00
parent f19f67c39c
commit 6e0fa02fd0
2 changed files with 21 additions and 2 deletions

View File

@ -1,3 +1,7 @@
2010-03-20 Nicolas François <nicolas.francois@centraliens.net>
* lib/groupio.c: Fix memory management insplit_groups().
2010-03-20 Nicolas François <nicolas.francois@centraliens.net> 2010-03-20 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/strtoday.c: Empty dates indicate a disabled date, this is * libmisc/strtoday.c: Empty dates indicate a disabled date, this is

View File

@ -382,6 +382,7 @@ static int split_groups (unsigned int max_members)
struct commonio_entry *new; struct commonio_entry *new;
struct group *new_gptr; struct group *new_gptr;
unsigned int members = 0; unsigned int members = 0;
int i;
/* Check if this group must be split */ /* Check if this group must be split */
if (!gr->changed) if (!gr->changed)
@ -408,9 +409,23 @@ static int split_groups (unsigned int max_members)
new->changed = true; new->changed = true;
/* Enforce the maximum number of members on gptr */ /* 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 */ /* 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 */ /* insert the new entry in the list */
new->prev = gr; new->prev = gr;