Bz/fix freebsd

Fix issues. Tested with freeBSD 9.2 and 10.
Yes, I am saying that nothing the documentation says that it won't be allocated if there is an error.