machine property: avoid hardcoded sizes/strings in sysctl, check err codes

Replaced the call to sysctlbyname with sysctl, avoiding string parsing.
 - used two calls in order to get actual string length
 - checked all calls to sysctl, return nil on error
 - checked call to malloc, return nil on error

Our lovely security analysis tool flagged this as a must-fix failure to check error conditions on the malloc. I've included an implementation with that and a few other enhancements.