diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 5d7ad96cfffaaff05b5d4e088d6a55148be076e7..d87e75c7702f72bc4a9dbad53685f1b04c886e17 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -749,6 +749,7 @@ runShellCommand(CState *st, char *variable, char **argv, int argc)
 	{
 		if (!timer_exceeded)
 			fprintf(stderr, "%s: cannot read the result\n", argv[0]);
+		(void) pclose(fp);
 		return false;
 	}
 	if (pclose(fp) < 0)