Require dos.library V39, not V40.
Fix numerous misc problems noticed by asman on PPA.

* Fix using freed memory in fib.
* Close open dos.library on errors.
* Free dos object on errors.
* Close file on errors.
* Make debug explicitely a BOOL extern.
Make debug extern explicitely a BOOL.