Fixes crash/valgrind errors in trac ticket 3188 and hang in 3274.
Attach a file by drag & drop or click to upload