https://bugs.gentoo.org/746419

This backports the following commit from upstream git:

commit 591c0f804b5a78421d28edf2adcd429c914bbca1
Author: Ethan A Merritt <merritt@u.washington.edu>
Date:   Wed Sep 9 11:00:59 2020 -0700

    successive failures of "set print <foo>" could cause double-free
    Bug #2312

--- gnuplot-5.2.8-orig/src/command.c
+++ gnuplot-5.2.8/src/command.c
@@ -1867,6 +1867,7 @@
 #endif
 	    if (0 > fclose(print_out))
 		perror(print_out_name);
+	print_out = stderr;
     }
 
     free(print_out_name);
