Fix for issue #454 (Thanks to koenigtm)

Two patches for "crash on close" issues without resorting to the compatibility flag.

Another heap corruption happens after building a simulated node due to an off-by-one error.

Signed-off-by: Tobias Lorenz <tobias.lorenz@etas.com>