peres: Fix an off-by-one heap overflow in saveResource.
       Add missing checkings for NULL pointer.
Merge pull request #43 from jweyrich/peres-fixes

peres: Fix an off-by-one heap overflow in saveResource.