Mdurnev/valgrind1

valgrind 3.8.1: Backport from master branch