The attached patch fixes this bug. This patch relies on the varhook feature. For details, see: https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00974.html