Index: trunk/src/VBox/Main/ConsoleImpl2.cpp
===================================================================
--- trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 28128)
+++ trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 28130)
@@ -72,8 +72,7 @@
 
 #ifdef VBOX_WITH_NETFLT
-# ifdef RT_OS_SOLARIS
+# if defined(RT_OS_SOLARIS)
 #  include <zone.h>
-# endif
-# ifdef RT_OS_LINUX
+# elif defined(RT_OS_LINUX)
 #  include <unistd.h>
 #  include <sys/ioctl.h>
@@ -82,6 +81,5 @@
 #  include <linux/if.h>
 #  include <linux/wireless.h>
-# endif
-# ifdef RT_OS_FREEBSD
+# elif defined(RT_OS_FREEBSD)
 #  include <unistd.h>
 #  include <sys/types.h>
@@ -91,5 +89,5 @@
 #  include <net80211/ieee80211_ioctl.h>
 # endif
-# ifdef RT_OS_WINDOWS
+# if defined(RT_OS_WINDOWS)
 #  include <VBox/WinNetConfig.h>
 #  include <Ntddndis.h>
@@ -114,5 +112,6 @@
      *   http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
      */
-    typedef struct {
+    typedef struct
+    {
         uint32_t   key;
         uint8_t    pad0[22];
@@ -153,5 +152,8 @@
                                        &outputStructCnt);
         if (kr != kIOReturnSuccess)
+        {
+            IOServiceClose(port);
             return VERR_INTERNAL_ERROR;
+        }
 
         for (int j=0; j<32; j++)
@@ -166,6 +168,7 @@
 }
 
-#endif
-
+#endif /* RT_OS_DARWIN */
+
+/* Darwin compile cludge */
 #undef PVM
 
@@ -304,5 +307,5 @@
 #define STR_FREE()  do { if (str) { SysFreeString(str); str = NULL; } } while (0)
 #define RC_CHECK()  do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc));  STR_FREE(); return rc;                   } } while (0)
-#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
+#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
 
     /*
@@ -348,5 +351,5 @@
 
     Bstr guestTypeFamilyId;
-    hrc = guestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam());       H();
+    hrc = guestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam());         H();
     BOOL fOsXGuest = guestTypeFamilyId == Bstr("MacOS");
 
@@ -375,4 +378,5 @@
     rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled",          1);     /* boolean */   RC_CHECK();
 #endif
+    STR_FREE();
 
     /* cpuid leaf overrides. */
@@ -493,21 +497,21 @@
     /* HWVirtEx exclusive mode */
     BOOL fHWVirtExExclusive = true;
-    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive);  H();
-    rc = CFGMR3InsertInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive);                     RC_CHECK();
+    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive); H();
+    rc = CFGMR3InsertInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive);          RC_CHECK();
 
     /* Nested paging (VT-x/AMD-V) */
     BOOL fEnableNestedPaging = false;
-    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging);   H();
-    rc = CFGMR3InsertInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging);     RC_CHECK();
+    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
+    rc = CFGMR3InsertInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
 
     /* Large pages; requires nested paging */
     BOOL fEnableLargePages = false;
-    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages);   H();
-    rc = CFGMR3InsertInteger(pHWVirtExt, "EnableLargePages", fEnableLargePages);     RC_CHECK();
+    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages); H();
+    rc = CFGMR3InsertInteger(pHWVirtExt, "EnableLargePages", fEnableLargePages);    RC_CHECK();
 
     /* VPID (VT-x) */
     BOOL fEnableVPID = false;
-    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID);        H();
-    rc = CFGMR3InsertInteger(pHWVirtExt, "EnableVPID", fEnableVPID);                     RC_CHECK();
+    hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID);   H();
+    rc = CFGMR3InsertInteger(pHWVirtExt, "EnableVPID", fEnableVPID);                RC_CHECK();
 
     /* Physical Address Extension (PAE) */
@@ -522,5 +526,5 @@
 
     BOOL fPXEDebug;
-    hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug);                      H();
+    hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug);                     H();
 
     /*
@@ -531,7 +535,7 @@
     PCFGMNODE pDrivers;
     PCFGMNODE pMod;
-    rc = CFGMR3InsertNode(pRoot,    "PDM", &pPDM);                                     RC_CHECK();
-    rc = CFGMR3InsertNode(pPDM,     "Drivers", &pDrivers);                             RC_CHECK();
-    rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod);                                   RC_CHECK();
+    rc = CFGMR3InsertNode(pRoot,    "PDM", &pPDM);                                  RC_CHECK();
+    rc = CFGMR3InsertNode(pPDM,     "Drivers", &pDrivers);                          RC_CHECK();
+    rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod);                                RC_CHECK();
 #ifdef VBOX_WITH_XPCOM
     // VBoxC is located in the components subdirectory
@@ -539,7 +543,7 @@
     rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
     strcat(szPathVBoxC, "/components/VBoxC");
-    rc = CFGMR3InsertString(pMod,   "Path",  szPathVBoxC);                             RC_CHECK();
+    rc = CFGMR3InsertString(pMod,   "Path",  szPathVBoxC);                          RC_CHECK();
 #else
-    rc = CFGMR3InsertString(pMod,   "Path",  "VBoxC");                                 RC_CHECK();
+    rc = CFGMR3InsertString(pMod,   "Path",  "VBoxC");                              RC_CHECK();
 #endif
 
@@ -549,10 +553,10 @@
     PCFGMNODE pPDMAc;
     PCFGMNODE pPDMAcFile;
-    rc = CFGMR3InsertNode(pPDM, "AsyncCompletion", &pPDMAc);                           RC_CHECK();
-    rc = CFGMR3InsertNode(pPDMAc, "File", &pPDMAcFile);                                RC_CHECK();
+    rc = CFGMR3InsertNode(pPDM, "AsyncCompletion", &pPDMAc);                        RC_CHECK();
+    rc = CFGMR3InsertNode(pPDMAc, "File", &pPDMAcFile);                             RC_CHECK();
 
     /* I/O manager type */
     IoMgrType_T ioMgrType;
-    hrc = pMachine->COMGETTER(IoMgr)(&ioMgrType);                                      H();
+    hrc = pMachine->COMGETTER(IoMgr)(&ioMgrType);                                   H();
     if (ioMgrType == IoMgrType_Async)
         rc = CFGMR3InsertString(pPDMAcFile, "IoMgr", "Async");
@@ -565,5 +569,5 @@
     /* I/O backend type */
     IoBackendType_T ioBackendType;
-    hrc = pMachine->COMGETTER(IoBackend)(&ioBackendType);                              H();
+    hrc = pMachine->COMGETTER(IoBackend)(&ioBackendType);                           H();
     if (ioBackendType == IoBackendType_Buffered)
         rc = CFGMR3InsertString(pPDMAcFile, "FileBackend", "Buffered");
@@ -576,15 +580,15 @@
     /* Builtin I/O cache */
     BOOL fIoCache = true;
-    hrc = pMachine->COMGETTER(IoCacheEnabled)(&fIoCache);                              H();
-    rc = CFGMR3InsertInteger(pPDMAcFile, "CacheEnabled", fIoCache);                    RC_CHECK();
+    hrc = pMachine->COMGETTER(IoCacheEnabled)(&fIoCache);                           H();
+    rc = CFGMR3InsertInteger(pPDMAcFile, "CacheEnabled", fIoCache);                 RC_CHECK();
 
     /* I/O cache size */
     ULONG ioCacheSize = 5;
-    hrc = pMachine->COMGETTER(IoCacheSize)(&ioCacheSize);                              H();
-    rc = CFGMR3InsertInteger(pPDMAcFile, "CacheSize", ioCacheSize * _1M);              RC_CHECK();
+    hrc = pMachine->COMGETTER(IoCacheSize)(&ioCacheSize);                           H();
+    rc = CFGMR3InsertInteger(pPDMAcFile, "CacheSize", ioCacheSize * _1M);           RC_CHECK();
 
     /* Maximum I/O bandwidth */
     ULONG ioBandwidthMax = 0;
-    hrc = pMachine->COMGETTER(IoBandwidthMax)(&ioBandwidthMax);                        H();
+    hrc = pMachine->COMGETTER(IoBandwidthMax)(&ioBandwidthMax);                     H();
     if (ioBandwidthMax != 0)
     {
@@ -683,7 +687,7 @@
     if (fHpetEnabled)
     {
-        rc = CFGMR3InsertNode(pDevices, "hpet", &pDev);                      RC_CHECK();
-        rc = CFGMR3InsertNode(pDev,     "0", &pInst);                        RC_CHECK();
-        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */   RC_CHECK();
+        rc = CFGMR3InsertNode(pDevices, "hpet", &pDev);                             RC_CHECK();
+        rc = CFGMR3InsertNode(pDev,     "0", &pInst);                               RC_CHECK();
+        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */          RC_CHECK();
     }
 
@@ -700,10 +704,10 @@
     {
         Bstr tmpStr2;
-        rc = CFGMR3InsertNode(pDevices, "smc", &pDev);                       RC_CHECK();
-        rc = CFGMR3InsertNode(pDev,     "0", &pInst);                        RC_CHECK();
-        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */   RC_CHECK();
-        rc = CFGMR3InsertNode(pInst,    "Config", &pCfg);                    RC_CHECK();
-        rc = getSmcDeviceKey(pMachine,   tmpStr2.asOutParam());              RC_CHECK();
-        rc = CFGMR3InsertString(pCfg,   "DeviceKey", Utf8Str(tmpStr2).raw());RC_CHECK();
+        rc = CFGMR3InsertNode(pDevices, "smc", &pDev);                              RC_CHECK();
+        rc = CFGMR3InsertNode(pDev,     "0", &pInst);                               RC_CHECK();
+        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */          RC_CHECK();
+        rc = CFGMR3InsertNode(pInst,    "Config", &pCfg);                           RC_CHECK();
+        rc = getSmcDeviceKey(pMachine,   tmpStr2.asOutParam());                     RC_CHECK();
+        rc = CFGMR3InsertString(pCfg,   "DeviceKey", Utf8Str(tmpStr2).raw());       RC_CHECK();
     }
 
@@ -720,7 +724,7 @@
     if (fLpcEnabled)
     {
-        rc = CFGMR3InsertNode(pDevices, "lpc", &pDev);                       RC_CHECK();
-        rc = CFGMR3InsertNode(pDev,     "0", &pInst);                        RC_CHECK();
-        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */   RC_CHECK();
+        rc = CFGMR3InsertNode(pDevices, "lpc", &pDev);                              RC_CHECK();
+        rc = CFGMR3InsertNode(pDev,     "0", &pInst);                               RC_CHECK();
+        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */          RC_CHECK();
     }
 
@@ -804,5 +808,5 @@
     BOOL fRTCUseUTC;
     hrc = pMachine->COMGETTER(RTCUseUTC)(&fRTCUseUTC);                              H();
-    rc = CFGMR3InsertInteger(pCfg,  "UseUTC", fRTCUseUTC ? 1 : 0);
+    rc = CFGMR3InsertInteger(pCfg,  "UseUTC", fRTCUseUTC ? 1 : 0);                  RC_CHECK();
 
     /*
@@ -871,5 +875,5 @@
     }
     STR_FREE();
-    rc = CFGMR3InsertInteger(pCfg,  "CustomVideoModes", cModes);
+    rc = CFGMR3InsertInteger(pCfg,  "CustomVideoModes", cModes);                    RC_CHECK();
 
     /* VESA height reduction */
@@ -1027,12 +1031,12 @@
         rc = CFGMR3InsertInteger(pCfg,  "NumCPUs",          cCpus);                 RC_CHECK();
         rc = CFGMR3InsertString(pCfg,   "EfiRom",           efiRomFile.raw());      RC_CHECK();
-        rc = CFGMR3InsertString(pCfg,   "BootArgs",         Utf8Str(bootArgs).raw());RC_CHECK();
-        rc = CFGMR3InsertString(pCfg,   "DeviceProps",      Utf8Str(deviceProps).raw());RC_CHECK();
+        rc = CFGMR3InsertString(pCfg,   "BootArgs",         Utf8Str(bootArgs).raw()); RC_CHECK();
+        rc = CFGMR3InsertString(pCfg,   "DeviceProps",      Utf8Str(deviceProps).raw()); RC_CHECK();
         rc = CFGMR3InsertInteger(pCfg,  "IOAPIC",           fIOAPIC);           RC_CHECK();
-        rc = CFGMR3InsertBytes(pCfg,    "UUID", &HardwareUuid,sizeof(HardwareUuid));RC_CHECK();
+        rc = CFGMR3InsertBytes(pCfg,    "UUID", &HardwareUuid,sizeof(HardwareUuid)); RC_CHECK();
         rc = CFGMR3InsertInteger(pCfg,  "64BitEntry", f64BitEntry); /* boolean */   RC_CHECK();
         rc = CFGMR3InsertInteger(pCfg,  "GopMode", u32GopMode);    RC_CHECK();
-        rc = CFGMR3InsertInteger(pCfg,  "UgaHorizontalResolution", u32UgaHorisontal);    RC_CHECK();
-        rc = CFGMR3InsertInteger(pCfg,  "UgaVerticalResolution", u32UgaVertical);    RC_CHECK();
+        rc = CFGMR3InsertInteger(pCfg,  "UgaHorizontalResolution", u32UgaHorisontal); RC_CHECK();
+        rc = CFGMR3InsertInteger(pCfg,  "UgaVerticalResolution", u32UgaVertical);   RC_CHECK();
 
         /* For OS X guests we'll force passing host's DMI info to the guest */
@@ -1653,8 +1657,8 @@
             PCFGMNODE pNetBtDevCfg;
             achBootIdx[0] = '0' + uBootIdx++;   /* Boot device order. */
-            rc = CFGMR3InsertNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg);      RC_CHECK();
-            rc = CFGMR3InsertInteger(pNetBtDevCfg, "NIC", it->mInstance);       RC_CHECK();
-            rc = CFGMR3InsertInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPciDev); RC_CHECK();
-            rc = CFGMR3InsertInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPciFn);RC_CHECK();
+            rc = CFGMR3InsertNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg);          RC_CHECK();
+            rc = CFGMR3InsertInteger(pNetBtDevCfg, "NIC", it->mInstance);           RC_CHECK();
+            rc = CFGMR3InsertInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPciDev);     RC_CHECK();
+            rc = CFGMR3InsertInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPciFn);    RC_CHECK();
         }
     }
@@ -2481,5 +2485,5 @@
 #define STR_FREE()  do { if (str) { SysFreeString(str); str = NULL; } } while (0)
 #define RC_CHECK()  do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc));  STR_FREE(); return rc;                   } } while (0)
-#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
+#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
 
     HRESULT hrc;
@@ -2593,5 +2597,7 @@
             hrc = natDriver->COMGETTER(Network)(&str);                  H();
             if (str)
+            {
                 rc = CFGMR3InsertStringW(pCfg, "Network", str);         RC_CHECK();
+            }
             STR_FREE();
             hrc = natDriver->COMGETTER(HostIP)(&str);                   H();
@@ -2693,5 +2699,5 @@
                 uint32_t proto = strProto.toUInt32();
                 bool fValid = true;
-                switch(proto)
+                switch (proto)
                 {
                     case NATProtocol_UDP:
