Index: generic/src/mm/frame.c
===================================================================
--- generic/src/mm/frame.c	(revision 7c7aae1655a7653ed95980918529a6c78e15b376)
+++ generic/src/mm/frame.c	(revision 9d3e1855e93f6f539485179792734488bb54fd7c)
@@ -538,7 +538,9 @@
 	}
 	/* Copy frames from both zones to preserve full frame orders,
-	 * parents etc. Set all frames with refcount=0 to 1, because
+	 * parents etc. Set all free frames with refcount=0 to 1, because
 	 * we add all free frames to buddy allocator later again, clear
-	 * order to 0.
+	 * order to 0. Don't set busy frames with refcount=0, as they
+	 * will not be reallocated during merge and it would make later
+	 * problems with allocation/free.
 	 */
 	for (i=0; i<z1->count; i++)
@@ -548,8 +550,15 @@
 		z->frames[z2idx] = z2->frames[i];
 	}
-	for (i=0; i < z->count; i++) {
-		if (!z->frames[i].refcount) {
+	i = 0;
+	while (i < z->count) {
+		if (z->frames[i].refcount) {
+			/* skip busy frames */
+			i += 1 << z->frames[i].buddy_order;
+		} else { /* Free frames, set refcount=1 */
+			/* All free frames have refcount=0, we need not
+			 * to check the order */
 			z->frames[i].refcount = 1;
 			z->frames[i].buddy_order = 0;
+			i++;
 		}
 	}
