restored the old code in 5.4/5 related to bug #66872

The crash is reproducable in 5.6+ only, so 5.4 and 5.5 are fine
with the old code.