Filling between data curves with filledcurve produces a set of quadrilaterals. In many PDF viewers, antialiased rendering can lead to seams appearing. This problem has been reported in various places, such as here, which includes a nice zoomed-in screenshot of the issue.
This problem can be avoided by rendering entire polygons rather than splitting the filled curve into quadrilaterals. I've implemented this in the attached patch (against gnuplot 5.0.5), and verified (using Evince) that the seams disappear.
After applying your patch to current cvs source for version 5.0
Inspection of output shows intended difference from unpatched output.
So far, so good.
However....
The memory corruption is too severe to catch in gdb, but perhaps the valgrind output is informative.
FYI but separate from whatever bug is present, the reason gnuplot draws filledcurves the way it does to avoid limitations in standard PostScript output. gnuplot orginally did something more similar to your approach but
1) Some postscript interpreters are limited to a certain maximum number of vertices defining a closed curve. Reasonable plots could exceed this maximum, making the output ps file unusable.
2) Accumulated round-off error in the coordinates can make the start/end points not meet up. This may be the reason that the interpreters impose a limit on the maximum number of vertices, but even if you don't exceed that maximum it can produce odd results.
Neither of these old problems applies to non-postscript output so far as I know, and maybe modern postscript implementations don't hit this anyhow, but I worry a bit. If you get your code fixed up we might still want to make it optional or only used by certain terminal types.
Sorry, that was a silly error. I've simplified the memory allocation slightly in this new version.
Applied to the development version (5.1).
Can be added for 5.0.7 if no problems are reported in the development version.