all: remove pointless NULL checks

g_malloc(), etc, never return NULL, by API contract. Likewise, by
extension, no other glib function ever returns NULL due to lack of
memory. So remove lots of unnecessary checks (the vast majority of
which would have immediately crashed had they ever run anyway, since
g_set_error(), g_warning(), and nm_log_*() all need to allocate
memory).

https://bugzilla.gnome.org/show_bug.cgi?id=693678
This commit is contained in:
Dan Winship
2013-01-31 15:36:12 -05:00
parent d0bfd47dfb
commit d04f286327
22 changed files with 15 additions and 244 deletions

View File

@@ -1118,16 +1118,7 @@ ip4_options_to_config (NMDHCPClient *self)
g_return_val_if_fail (priv->options != NULL, NULL);
ip4_config = nm_ip4_config_new ();
if (!ip4_config) {
nm_log_warn (LOGD_DHCP4, "(%s): couldn't allocate memory for an IP4Config!", priv->iface);
return NULL;
}
addr = nm_ip4_address_new ();
if (!addr) {
nm_log_warn (LOGD_DHCP4, "(%s): couldn't allocate memory for an IP4 Address!", priv->iface);
goto error;
}
str = g_hash_table_lookup (priv->options, "new_ip_address");
if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
@@ -1333,10 +1324,6 @@ ip6_options_to_config (NMDHCPClient *self)
}
ip6_config = nm_ip6_config_new ();
if (!ip6_config) {
nm_log_warn (LOGD_DHCP6, "(%s): couldn't allocate memory for an IP6Config!", priv->iface);
return NULL;
}
str = g_hash_table_lookup (priv->options, "new_ip6_address");
if (str) {

View File

@@ -474,10 +474,6 @@ dhclient_start (NMDHCPClient *client,
pid_file = g_strdup_printf (LOCALSTATEDIR "/run/dhclient%s-%s.pid",
ipv6 ? "6" : "",
iface);
if (!pid_file) {
nm_log_warn (log_domain, "(%s): not enough memory for dhcpcd options.", iface);
return -1;
}
/* Kill any existing dhclient from the pidfile */
binary_name = g_path_get_basename (priv->path);
@@ -492,10 +488,6 @@ dhclient_start (NMDHCPClient *client,
g_free (priv->lease_file);
priv->lease_file = get_dhclient_leasefile (iface, uuid, ipv6);
if (!priv->lease_file) {
nm_log_warn (log_domain, "(%s): not enough memory for dhclient options.", iface);
return -1;
}
argv = g_ptr_array_new ();
g_ptr_array_add (argv, (gpointer) priv->path);

View File

@@ -111,10 +111,6 @@ ip4_start (NMDHCPClient *client,
uuid = nm_dhcp_client_get_uuid (client);
priv->pid_file = g_strdup_printf (NMSTATEDIR "/dhcpcd-%s.pid", iface);
if (!priv->pid_file) {
nm_log_warn (LOGD_DHCP4, "(%s): not enough memory for dhcpcd options.", iface);
return -1;
}
if (!g_file_test (priv->path, G_FILE_TEST_EXISTS)) {
nm_log_warn (LOGD_DHCP4, "%s does not exist.", priv->path);