diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 207fdda..0b2ce65 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -703,12 +703,14 @@ function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE)
       $_SESSION['messages'][$type] = array();
     }
 
-    if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {
-      $_SESSION['messages'][$type][] = array(
-        'safe' => SafeMarkup::isSafe($message),
-        'message' => $message,
-      );
+    $new = array(
+      'safe' => SafeMarkup::isSafe($message),
+      'message' => $message,
+    );
+    if ($repeat || !in_array($new, $_SESSION['messages'][$type])) {
+      $_SESSION['messages'][$type][] = $new;
     }
+    unset($new);
 
     // Mark this page as being uncacheable.
     \Drupal::service('page_cache_kill_switch')->trigger();
