patch 8.1.0552: saved last search pattern may not be restored

Problem:    Saved last search pattern may not be restored.
Solution:   Call restore_last_search_pattern().  Add a check for balancing
            saving and restoring the last search pattern.
diff --git a/src/ex_getln.c b/src/ex_getln.c
index acccd27..bfda942 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -462,6 +462,7 @@
     int		use_last_pat;
 
     // Parsing range may already set the last search pattern.
+    // NOTE: must call restore_last_search_pattern() before returning!
     save_last_search_pattern();
 
     if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
@@ -633,6 +634,7 @@
     int	    save;
 
     // Parsing range may already set the last search pattern.
+    // NOTE: must call restore_last_search_pattern() before returning!
     save_last_search_pattern();
 
     if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
@@ -735,6 +737,7 @@
     int		skiplen, patlen;
 
     // Parsing range may already set the last search pattern.
+    // NOTE: must call restore_last_search_pattern() before returning!
     save_last_search_pattern();
 
     if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
@@ -742,6 +745,7 @@
 	restore_last_search_pattern();
 	return FAIL;
     }
+    restore_last_search_pattern();
 
     // Add a character from under the cursor for 'incsearch'.
     if (is_state->did_incsearch)
diff --git a/src/search.c b/src/search.c
index 98665f7..d7aa592 100644
--- a/src/search.c
+++ b/src/search.c
@@ -96,6 +96,7 @@
 /* copy of spats[RE_SEARCH], for keeping the search patterns while incremental
  * searching */
 static struct spat  saved_last_search_spat;
+static int	    did_save_last_search_spat = 0;
 static int	    saved_last_idx = 0;
 static int	    saved_no_hlsearch = 0;
 # endif
@@ -364,6 +365,11 @@
     void
 save_last_search_pattern(void)
 {
+    if (did_save_last_search_spat != 0)
+	IEMSG("did_save_last_search_spat is not zero");
+    else
+	++did_save_last_search_spat;
+
     saved_last_search_spat = spats[RE_SEARCH];
     if (spats[RE_SEARCH].pat != NULL)
 	saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat);
@@ -374,8 +380,16 @@
     void
 restore_last_search_pattern(void)
 {
+    if (did_save_last_search_spat != 1)
+    {
+	IEMSG("did_save_last_search_spat is not one");
+	return;
+    }
+    --did_save_last_search_spat;
+
     vim_free(spats[RE_SEARCH].pat);
     spats[RE_SEARCH] = saved_last_search_spat;
+    saved_last_search_spat.pat = NULL;
 # if defined(FEAT_EVAL)
     set_vv_searchforward();
 # endif
diff --git a/src/version.c b/src/version.c
index 29f3ec5..1fc35ed 100644
--- a/src/version.c
+++ b/src/version.c
@@ -793,6 +793,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    552,
+/**/
     551,
 /**/
     550,