Fixed refcounting errors flagged in https://bugzilla.redhat.com/show_bug.cgi?id=809425
avoid dereferencing NULLs returned when running out of memory