Index: postgis/lwgeom_accum.c
===================================================================
--- postgis/lwgeom_accum.c	(revision 5449)
+++ postgis/lwgeom_accum.c	(working copy)
@@ -155,6 +155,9 @@
 	ArrayBuildState *state;
 	Datum result;
 
+	if (PG_ARGISNULL(0))
+		PG_RETURN_NULL(); /* returns null iff no input values */
+
 	/* cannot be called directly because of internal-type argument */
 	Assert(fcinfo->context &&
 	       (IsA(fcinfo->context, AggState)
@@ -169,9 +172,7 @@
 #if POSTGIS_PGSQL_VERSION < 84
 	result = makeMdArrayResult(state, 1, dims, lbs, mctx);
 #else
-	/* Release working state if regular aggregate, but not if window agg */
-	result = makeMdArrayResult(state, 1, dims, lbs, mctx,
-	                           IsA(fcinfo->context, AggState));
+	result = makeMdArrayResult(state, 1, dims, lbs, mctx, false);
 #endif
 	return result;
 }
