distance: do not allocate large array on the stack

Closes rhbz#951544.

Signed-off-by: Martin Milata <mmilata@redhat.com>