backport from 1.9 (rev #10001)

do not mess up existing dialog legs in case re-sizing the legs array fails due to no more share mem