updated for version 7.3.1018
Problem:    New regexp engine wastes memory.
Solution:   Allocate prog with actual number of states, not estimated maximum
            number of sates.
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index 10b6af5..2732163 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -3758,7 +3758,7 @@
     char_u	*expr;
     int		re_flags;
 {
-    nfa_regprog_T	*prog;
+    nfa_regprog_T	*prog = NULL;
     size_t		prog_size;
     int			*postfix;
 
@@ -3774,15 +3774,8 @@
     if (nfa_regcomp_start(expr, re_flags) == FAIL)
 	return NULL;
 
-    /* Space for compiled regexp */
-    prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate_max;
-    prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
-    if (prog == NULL)
-	goto fail;
-    vim_memset(prog, 0, prog_size);
-
     /* Build postfix form of the regexp. Needed to build the NFA
-     * (and count its size) */
+     * (and count its size). */
     postfix = re2post();
     if (postfix == NULL)
 	goto fail;	    /* Cascaded (syntax?) error */
@@ -3809,6 +3802,13 @@
      * Count number of NFA states in "nstate". Do not build the NFA.
      */
     post2nfa(postfix, post_ptr, TRUE);
+
+    /* Space for compiled regexp */
+    prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate;
+    prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
+    if (prog == NULL)
+	goto fail;
+    vim_memset(prog, 0, prog_size);
     state_ptr = prog->state;
 
     /*
diff --git a/src/version.c b/src/version.c
index 6d745d3..ed45156 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1018,
+/**/
     1017,
 /**/
     1016,