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 #4082 from jakesmith/hpcc-8905-master

HPCC-8905 Fix minisort OOM and deadlock

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>