diff --git a/src/kernel/group.c b/src/kernel/group.c index 19f816b13..600c5c6ab 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -125,10 +125,14 @@ attrib_type at_group = { /* attribute for units assigned to a group */ void free_group(group * g) { - int index = g->gid % GMAXHASH; - group **g_ptr = ghash + index; - while (*g_ptr && (*g_ptr)->gid != g->gid) + int index; + group **g_ptr; + assert(g); + index = g->gid % GMAXHASH; + g_ptr = ghash + index; + while (*g_ptr && (*g_ptr)->gid != g->gid) { g_ptr = &(*g_ptr)->nexthash; + } assert(*g_ptr == g); *g_ptr = g->nexthash; diff --git a/src/kernel/group.test.c b/src/kernel/group.test.c index 7fa7fa234..d8663d7b8 100644 --- a/src/kernel/group.test.c +++ b/src/kernel/group.test.c @@ -91,6 +91,7 @@ static void test_group_readwrite(CuTest * tc) write_groups(&store, f); WRITE_INT(&store, 47); + free_group(f->groups); free_group(g); f->groups = 0; data.strm.api->rewind(data.strm.handle);