Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / metadata / mono-route.c
index e6e397af0ec7cd4bca2b842d3d39b8a6cc3e003e..c90af3cdfe33b8b89d1ce23f65a14e42046ff636 100644 (file)
@@ -7,8 +7,9 @@
  *   Ben Woods (woodsb02@gmail.com)
  */
 
-#if defined(PLATFORM_MACOSX) || defined(PLATFORM_BSD)
+#include <config.h>
 
+#if defined(HOST_DARWIN) || defined(HOST_BSD)
 #include <sys/socket.h>
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -58,8 +59,10 @@ extern MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfacePrope
                return FALSE;
 
        // Second sysctl call to retrieve data into appropriately sized buffer
-       if (sysctl(mib, G_N_ELEMENTS(mib), buf, &needed, NULL, 0) < 0)
+       if (sysctl(mib, G_N_ELEMENTS(mib), buf, &needed, NULL, 0) < 0) {
+               g_free (buf);
                return FALSE;
+       }
 
        lim = buf + needed;
        for (next = buf; next < lim; next += rtm->rtm_msglen) {
@@ -73,7 +76,9 @@ extern MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfacePrope
                num_gws++;
        }
 
-       *gw_addr_list = mono_array_new(domain, mono_get_string_class (), num_gws);
+       *gw_addr_list = mono_array_new_checked (domain, mono_get_string_class (), num_gws, &error);
+       if (!is_ok (&error))
+               goto leave;
 
        for (next = buf; next < lim; next += rtm->rtm_msglen) {
                rtm = (struct rt_msghdr *)next;
@@ -99,12 +104,15 @@ extern MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfacePrope
                        // snprintf output truncated
                        continue;
 
-               addr_string = mono_string_new (domain, addr);
+               addr_string = mono_string_new_checked (domain, addr, &error);
+               if (!is_ok (&error))
+                       goto leave;
                mono_array_setref (*gw_addr_list, gwnum, addr_string);
                gwnum++;
        }
+leave:
        g_free (buf);
-       return TRUE;
+       return is_ok (&error);
 }
 
 in_addr_t gateway_from_rtm(struct rt_msghdr *rtm)
@@ -126,4 +134,4 @@ in_addr_t gateway_from_rtm(struct rt_msghdr *rtm)
        return 0;
 }
 
-#endif /* #if defined(PLATFORM_MACOSX) || defined(PLATFORM_BSD) */
+#endif /* #if defined(HOST_DARWIN) || defined(HOST_BSD) */