hpcc-8905 Fix minisort OOM and deadlock

Various problems causing mini sort to miscalculate in-memory
size, run out of memory and potentially deadlock

Signed-off-by: Jake Smith <jake.smith@lexisnexis.com>
Merge pull request #4077 from jakesmith/hpcc-8905

HPCC-8905 Fix minisort OOM and deadlock

Reviewed-By: Gavin Halliday <gavin.halliday@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>