Start pushing document.c to return on memory failure, not exit.  While here, push some code around (doesn't change anything) and add some more documentation.
Start pushing document.c to return on memory failure, not exit.  While here,
push some code around (doesn't change anything) and add some more documentation.

kristapsdz/lowdown,kristapsdz/lowdown,kristapsdz/lowdown