This reverts commit 935e241fa6. Issue will be fixed in a more localized way for now (not that nice, since this use-after-free can possibly happen in other places too, but only safe solution for 2.77). This commit is to be backported in 2.77.
935e241fa6