Fix a typo in the unit test

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Fix an off-by-one in the unit test

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Fix an fd leak spotted by the unit test

All the unit tests now pass again (vacuously true before, now
a single solitary test passes)

Signed-off-by: David Scott <dave.scott@eu.citrix.com>