See: https://bugs.kde.org/show_bug.cgi?id=378732 https://lists.gnu.org/archive/html/bug-bash/2017-04/msg00042.html
The problem, in short, is that valgrind does not intercept the malloc call (which is made via bash's built-in malloc), but does intercept the free call, and hence concludes that the free is invalid. A workaround is to build bash with --without-bash-malloc (but I presume there's a good reason not to do that?). -- http://rrt.sc3d.org