Mark various functions as pure.

Also workaround purity of malloc and free in util.array.