How to use Valgrind on FUSE filesystems

Hunting memory leaks, I’ve faced the problem of using Valgrind on a FUSE filesysem. Since fusermount is a SUIDed executable, Valgrind somehow interfere with filesystem mounting.

Here is a solution I’ve found searching on the Net:

# cd /usr/bin
# if [[ -e fusermount ]]; then mv fusermount fusermount.real; fi
# touch fusermount
# chown root.fuse fusermount
# chmod ug+x fusermount
# echo '#!/bin/sh' >> fusermount
# echo 'exec /usr/bin/fusermount.real $@' >> fusermount
[ or depending on the path of fusermount ]
# echo 'exec /bin/fusermount $@' >> fusermount 

The original resource about that seems to be gone forever.