diff --git a/src/multiset.c b/src/multiset.c
index 351662bdd6a01cee3143284726d99edf081d0221..44fc0c63ae064dc75433e171325c2f700c93f17a 100644
--- a/src/multiset.c
+++ b/src/multiset.c
@@ -1429,7 +1429,7 @@ union msnode *low_multiset_find_eq (struct multiset *l, struct svalue *key)
       /* Try again with tracking to be able to remove the destructed node. */
       RBSTACK_INIT (rbstack);
 
-      while (1) {
+      while (msd->root) {
 	enum find_types find_type = low_multiset_track_eq (msd, key, &rbstack);
 
 	if (l->msd != msd)
@@ -1450,10 +1450,11 @@ union msnode *low_multiset_find_eq (struct multiset *l, struct svalue *key)
 	  goto done;
 	}
       }
-
-      /* NOT REACHED */
+      node = NULL;
+      RBSTACK_FREE (rbstack);
+      goto done;
     }
-  }
+  } /* while(1) */
 
 done:
   UNSET_ONERROR (uwp);