diff --git a/src/backend/executor/nodeResult.c b/src/backend/executor/nodeResult.c
index 94796d5..ed437a0 100644
--- a/src/backend/executor/nodeResult.c
+++ b/src/backend/executor/nodeResult.c
@@ -91,6 +91,9 @@ ExecResult(ResultState *node)
 		}
 	}
 
+	/* release memory associated with the previous tuple */
+	ResetExprContext(econtext);
+
 	/*
 	 * Check to see if we're still projecting out tuples from a previous scan
 	 * tuple (because there is a function-returning-set in the projection
@@ -106,13 +109,6 @@ ExecResult(ResultState *node)
 	}
 
 	/*
-	 * Reset per-tuple memory context to free any expression evaluation
-	 * storage allocated in the previous tuple cycle.  Note this can't happen
-	 * until we're done projecting out tuples from a scan tuple.
-	 */
-	ResetExprContext(econtext);
-
-	/*
 	 * if rs_done is true then it means that we were asked to return a
 	 * constant tuple and we already did the last time ExecResult() was
 	 * called, OR that we failed the constant qual check. Either way, now we
