--- a/server-fn.c
+++ b/server-fn.c
@@ -398,14 +398,15 @@
 server_destroy_session_group(struct session *s)
 {
 	struct session_group	*sg;
+	struct session		*s1;
 
 	if ((sg = session_group_find(s)) == NULL)
 		server_destroy_session(s);
 	else {
-		TAILQ_FOREACH(s, &sg->sessions, gentry)
+		TAILQ_FOREACH_SAFE(s, &sg->sessions, gentry, s1) {
 			server_destroy_session(s);
-		TAILQ_REMOVE(&session_groups, sg, entry);
-		free(sg);
+			session_destroy(s);
+		}
 	}
 }