[PATCH] dbus: Don't pass NULL message ptr to dbus_message_new_error()

Dan Williams dcbw at redhat.com
Wed Jul 27 12:46:36 EDT 2011


On Mon, 2011-07-25 at 16:48 -0700, Angie Chinchilla wrote:
> Found at least 10 code paths that mistakenly assume
> message is not NULL before invoking
> dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL).
> Created a wrapper method wpas_dbus_error_no_memory() that
> checks for this case and returns NULL if needed so we don't
> have if (!message) return NULL else return dbus_message_new_error()
> blocks scattered all over the code. Also added a couple of log
> messages to the path that hits this error so the (now gracefully
> handled) errors don't fail silently.

I've actually just significantly reworked the new dbus interface code to
fix this problem and clean it up a bunch.  So Jouni, if you don't mind
waiting for my patch for this issue, that'd be great and we can make a
determination then.

Dan

> Signed-off-by: Angie Chinchilla <angie.v.chinchilla at intel.com>
> ---
>  wpa_supplicant/dbus/dbus_new_handlers.c     |  153 ++++++++++++---------------
>  wpa_supplicant/dbus/dbus_new_handlers.h     |    4 +
>  wpa_supplicant/dbus/dbus_new_handlers_p2p.c |   32 ++----
>  wpa_supplicant/dbus/dbus_new_handlers_wps.c |   13 +--
>  wpa_supplicant/dbus/dbus_new_helpers.c      |   14 +++-
>  5 files changed, 103 insertions(+), 113 deletions(-)
> 
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
> index 7c4218b..2360eb3 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers.c
> +++ b/wpa_supplicant/dbus/dbus_new_handlers.c
> @@ -124,6 +124,35 @@ DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
>  	return reply;
>  }
>  
> +/**
> + * wpas_dbus_error_no_memory - Return a new NoMemory error message
> + * @message: Pointer to incoming dbus message this error refers to
> + * @arg: Optional string appended to error message
> + * Returns: a dbus error message
> + *
> + * Convenience function to create and return a NoMemory error
> + */
> +DBusMessage * wpas_dbus_error_no_memory(DBusMessage *message,
> +					const char *arg)
> +{
> +	/*
> +	 * This function can be called as a result of a failure
> +	 * within internal getter calls, which will call this function
> +	 * with a NULL message parameter.  However, dbus_message_new_error
> +	 * looks very unkindly (i.e, abort()) on a NULL message, so
> +	 * in this case, we should not call it.
> +	 */
> +	if (message == NULL) {
> +		wpa_printf(MSG_INFO, "dbus: wpas_dbus_error_no_memory "
> +			   "called with NULL message (arg=%s)",
> +			   arg ? arg : "N/A");
> +		return NULL;
> +	}
> +
> +	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> +				      arg);
> +}
> +
>  
>  static const char *dont_quote[] = {
>  	"key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
> @@ -314,15 +343,12 @@ DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
>  				   "memory to put property value into "
>  				   "message");
>  			dbus_message_unref(reply);
> -			reply = dbus_message_new_error(message,
> -						       DBUS_ERROR_NO_MEMORY,
> -						       NULL);
> +			reply = wpas_dbus_error_no_memory(message, NULL);
>  		}
>  	} else {
>  		wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
>  			   " out of memory to return property value");
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	return reply;
> @@ -352,8 +378,7 @@ DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
>  	if (!dbus_message_iter_init(message, &iter)) {
>  		wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
>  			   " out of memory to return scanning state");
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	/* omit first and second argument and get value from third */
> @@ -414,8 +439,7 @@ DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
>  		wpa_printf(MSG_ERROR, "dbus: "
>  			   "wpas_dbus_simple_array_property_getter: out of "
>  			   "memory to create return message");
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	dbus_message_iter_init_append(reply, &iter);
> @@ -428,8 +452,7 @@ DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
>  			   "wpas_dbus_simple_array_property_getter: out of "
>  			   "memory to open container");
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	switch(type) {
> @@ -475,8 +498,7 @@ DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
>  			   "wpas_dbus_simple_array_property_getter: out of "
>  			   "memory to close container");
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	return reply;
> @@ -649,13 +671,11 @@ DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
>  	path = wpa_s->dbus_new_path;
>  	reply = dbus_message_new_method_return(message);
>  	if (reply == NULL)
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
>  				      DBUS_TYPE_INVALID)) {
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	return reply;
> @@ -832,8 +852,7 @@ DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
>  
>  	paths = os_zalloc(num * sizeof(char*));
>  	if (!paths) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
> @@ -866,8 +885,7 @@ DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message, void *nothing)
>  
>  	eap_methods = eap_get_names_as_string_array(&num_items);
>  	if (!eap_methods) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	reply = wpas_dbus_simple_array_property_getter(message,
> @@ -952,8 +970,8 @@ static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
>  					   "wpas_dbus_handler_scan[dbus]: "
>  					   "out of memory. Cannot allocate "
>  					   "memory for SSID");
> -				*reply = dbus_message_new_error(
> -					message, DBUS_ERROR_NO_MEMORY, NULL);
> +				*reply = wpas_dbus_error_no_memory(message,
> +								   NULL);
>  				return -1;
>  			}
>  			os_memcpy(ssid, val, len);
> @@ -1021,8 +1039,7 @@ static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
>  				   "out of memory. Cannot allocate memory for "
>  				   "IE");
>  			os_free(ies);
> -			*reply = dbus_message_new_error(
> -				message, DBUS_ERROR_NO_MEMORY, NULL);
> +			*reply = wpas_dbus_error_no_memory(message, NULL);
>  			return -1;
>  		}
>  		ies = nies;
> @@ -1116,8 +1133,7 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
>  			wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
>  				   "out of memory. can't allocate memory for "
>  				   "freqs");
> -			*reply = dbus_message_new_error(
> -				message, DBUS_ERROR_NO_MEMORY, NULL);
> +			*reply = wpas_dbus_error_no_memory(message, NULL);
>  			return -1;
>  		}
>  
> @@ -1135,8 +1151,7 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
>  	if (freqs == NULL) {
>  		wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
>  			   "out of memory. Can't allocate memory for freqs");
> -		*reply = dbus_message_new_error(
> -			message, DBUS_ERROR_NO_MEMORY, NULL);
> +		*reply = wpas_dbus_error_no_memory(message, NULL);
>  		return -1;
>  	}
>  	freqs[freqs_num] = 0;
> @@ -1320,15 +1335,13 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
>  
>  	reply = dbus_message_new_method_return(message);
>  	if (reply == NULL) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  	if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
>  				      DBUS_TYPE_INVALID)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  
> @@ -1527,15 +1540,13 @@ DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
>  
>  	blob = os_zalloc(sizeof(*blob));
>  	if (!blob) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  
>  	blob->data = os_malloc(blob_len);
>  	if (!blob->data) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  	os_memcpy(blob->data, blob_data, blob_len);
> @@ -1543,8 +1554,7 @@ DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
>  	blob->len = blob_len;
>  	blob->name = os_strdup(blob_name);
>  	if (!blob->name) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  
> @@ -1592,8 +1602,7 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
>  
>  	reply = dbus_message_new_method_return(message);
>  	if (!reply) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
> @@ -1603,23 +1612,20 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
>  					      DBUS_TYPE_BYTE_AS_STRING,
>  					      &array_iter)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
>  	if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
>  						  &(blob->data), blob->len)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
>  	if (!dbus_message_iter_close_container(&iter, &array_iter)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
> @@ -2015,7 +2021,7 @@ nomem:
>  	if (reply)
>  		dbus_message_unref(reply);
>  
> -	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	return wpas_dbus_error_no_memory(message, NULL);
>  }
>  
> 
> @@ -2041,8 +2047,7 @@ DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
>  	 */
>  	state_ls = tmp = os_strdup(str_state);
>  	if (!tmp) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  	while (*tmp) {
>  		*tmp = tolower(*tmp);
> @@ -2453,17 +2458,14 @@ DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
>  
>  	paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
>  	if (!paths) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	/* Loop through scan results and append each result's object path */
>  	dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
>  		paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
>  		if (paths[i] == NULL) {
> -			reply = dbus_message_new_error(message,
> -						       DBUS_ERROR_NO_MEMORY,
> -						       NULL);
> +			reply = wpas_dbus_error_no_memory(message, NULL);
>  			goto out;
>  		}
>  		/* Construct the object path for this BSS. */
> @@ -2513,8 +2515,7 @@ DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
>  
>  	paths = os_zalloc(num * sizeof(char *));
>  	if (!paths) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	/* Loop through configured networks and append object path of each */
> @@ -2523,9 +2524,7 @@ DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
>  			continue;
>  		paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
>  		if (paths[i] == NULL) {
> -			reply = dbus_message_new_error(message,
> -						       DBUS_ERROR_NO_MEMORY,
> -						       NULL);
> +			reply = wpas_dbus_error_no_memory(message, NULL);
>  			goto out;
>  		}
>  
> @@ -2567,8 +2566,7 @@ DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
>  	else
>  		reply = dbus_message_new_method_return(message);
>  	if (!reply)
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  
>  	dbus_message_iter_init_append(reply, &iter);
>  
> @@ -2577,8 +2575,7 @@ DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
>  	    !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
>  					      "{say}", &dict_iter)) {
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	blob = wpa_s->conf->blobs;
> @@ -2602,9 +2599,7 @@ DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
>  		    !dbus_message_iter_close_container(&dict_iter,
>  						       &entry_iter)) {
>  			dbus_message_unref(reply);
> -			return dbus_message_new_error(message,
> -						      DBUS_ERROR_NO_MEMORY,
> -						      NULL);
> +			return wpas_dbus_error_no_memory(message, NULL);
>  		}
>  
>  		blob = blob->next;
> @@ -2613,8 +2608,7 @@ DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
>  	if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
>  	    !dbus_message_iter_close_container(&iter, &variant_iter)) {
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	return reply;
> @@ -2812,8 +2806,7 @@ DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
>  	real_rates = os_malloc(sizeof(u32) * rates_num);
>  	if (!real_rates) {
>  		os_free(ie_rates);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	for (i = 0; i < rates_num; i++)
> @@ -2937,7 +2930,7 @@ nomem:
>  	if (reply)
>  		dbus_message_unref(reply);
>  
> -	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	return wpas_dbus_error_no_memory(message, NULL);
>  }
>  
> 
> @@ -3104,16 +3097,14 @@ DBusMessage * wpas_dbus_getter_network_properties(
>  	char **iterator;
>  	char **props = wpa_config_get_all(net->ssid, 1);
>  	if (!props)
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  
>  	if (message == NULL)
>  		reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
>  	else
>  		reply = dbus_message_new_method_return(message);
>  	if (!reply) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
> @@ -3123,8 +3114,7 @@ DBusMessage * wpas_dbus_getter_network_properties(
>  			"a{sv}", &variant_iter) ||
>  	    !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
> @@ -3133,9 +3123,7 @@ DBusMessage * wpas_dbus_getter_network_properties(
>  		if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
>  						 *(iterator + 1))) {
>  			dbus_message_unref(reply);
> -			reply = dbus_message_new_error(message,
> -						       DBUS_ERROR_NO_MEMORY,
> -						       NULL);
> +			reply = wpas_dbus_error_no_memory(message, NULL);
>  			goto out;
>  		}
>  		iterator += 2;
> @@ -3145,8 +3133,7 @@ DBusMessage * wpas_dbus_getter_network_properties(
>  	if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
>  	    !dbus_message_iter_close_container(&iter, &variant_iter)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto out;
>  	}
>  
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h
> index 978ee4c..1e84327 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers.h
> +++ b/wpa_supplicant/dbus/dbus_new_handlers.h
> @@ -222,7 +222,11 @@ DBusMessage * wpas_dbus_getter_credentials(DBusMessage *message,
>  
>  DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
>  					   const char *arg);
> +
>  DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
>  					    const char *arg);
>  
> +DBusMessage * wpas_dbus_error_no_memory(DBusMessage *message,
> +					const char *arg);
> +
>  #endif /* CTRL_IFACE_DBUS_HANDLERS_NEW_H */
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
> index 28c4198..0d99d2f 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
> +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
> @@ -170,12 +170,10 @@ DBusMessage * wpas_dbus_handler_p2p_listen(DBusMessage *message,
>  
>  	if (!dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &timeout,
>  				   DBUS_TYPE_INVALID))
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  
>  	if (wpas_p2p_listen(wpa_s, (unsigned int)timeout))
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  
>  	return NULL;
>  }
> @@ -797,7 +795,7 @@ DBusMessage * wpas_dbus_getter_p2p_device_properties(
>  	return reply;
>  err_no_mem:
>  	dbus_message_unref(reply);
> -	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	return wpas_dbus_error_no_memory(message, NULL);
>  }
>  
> 
> @@ -960,7 +958,7 @@ DBusMessage * wpas_dbus_setter_p2p_device_properties(
>  	return reply;
>   err_no_mem_clear:
>  	wpa_dbus_dict_entry_clear(&entry);
> -	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	return wpas_dbus_error_no_memory(message, NULL);
>  }
>  
> 
> @@ -1036,8 +1034,7 @@ error:
>  		os_free(node);
>  	}
>  	if (out_of_mem)
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  
>  	return reply;
>  }
> @@ -1247,7 +1244,7 @@ DBusMessage * wpas_dbus_getter_p2p_peer_properties(
>  	return reply;
>  err_no_mem:
>  	dbus_message_unref(reply);
> -	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	return wpas_dbus_error_no_memory(message, NULL);
>  }
>  
> 
> @@ -1288,8 +1285,7 @@ DBusMessage * wpas_dbus_getter_persistent_groups(DBusMessage *message,
>  
>  	paths = os_zalloc(num * sizeof(char *));
>  	if (!paths) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	/* Loop through configured networks and append object path of each */
> @@ -1298,9 +1294,7 @@ DBusMessage * wpas_dbus_getter_persistent_groups(DBusMessage *message,
>  			continue;
>  		paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
>  		if (paths[i] == NULL) {
> -			reply = dbus_message_new_error(message,
> -						       DBUS_ERROR_NO_MEMORY,
> -						       NULL);
> +			reply = wpas_dbus_error_no_memory(message, NULL);
>  			goto out;
>  		}
>  		/* Construct the object path for this network. */
> @@ -1434,15 +1428,13 @@ DBusMessage * wpas_dbus_handler_add_persistent_group(
>  
>  	reply = dbus_message_new_method_return(message);
>  	if (reply == NULL) {
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  	if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
>  				      DBUS_TYPE_INVALID)) {
>  		dbus_message_unref(reply);
> -		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					       NULL);
> +		reply = wpas_dbus_error_no_memory(message, NULL);
>  		goto err;
>  	}
>  
> @@ -1619,7 +1611,7 @@ DBusMessage * wpas_dbus_getter_p2p_group_members(DBusMessage *message,
>  	return reply;
>  
>  out_of_memory:
> -	reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	reply = wpas_dbus_error_no_memory(message, NULL);
>  	if (paths) {
>  		for (i = 0; i < num_members; i++)
>  			os_free(paths[i]);
> @@ -1680,7 +1672,7 @@ DBusMessage * wpas_dbus_getter_p2p_group_properties(
>  
>  err_no_mem:
>  	dbus_message_unref(reply);
> -	return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
> +	return wpas_dbus_error_no_memory(message, NULL);
>  }
>  
> 
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers_wps.c b/wpa_supplicant/dbus/dbus_new_handlers_wps.c
> index c118d73..7b830d3 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers_wps.c
> +++ b/wpa_supplicant/dbus/dbus_new_handlers_wps.c
> @@ -250,30 +250,25 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
>  
>  	reply = dbus_message_new_method_return(message);
>  	if (!reply) {
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	dbus_message_iter_init_append(reply, &iter);
>  	if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	if (os_strlen(npin) > 0) {
>  		if (!wpa_dbus_dict_append_string(&dict_iter, "Pin", npin)) {
>  			dbus_message_unref(reply);
> -			return dbus_message_new_error(message,
> -						      DBUS_ERROR_NO_MEMORY,
> -						      NULL);
> +			return wpas_dbus_error_no_memory(message, NULL);
>  		}
>  	}
>  
>  	if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
>  		dbus_message_unref(reply);
> -		return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
> -					      NULL);
> +		return wpas_dbus_error_no_memory(message, NULL);
>  	}
>  
>  	return reply;
> diff --git a/wpa_supplicant/dbus/dbus_new_helpers.c b/wpa_supplicant/dbus/dbus_new_helpers.c
> index 78611d4..005cfa6 100644
> --- a/wpa_supplicant/dbus/dbus_new_helpers.c
> +++ b/wpa_supplicant/dbus/dbus_new_helpers.c
> @@ -99,11 +99,18 @@ static unsigned int fill_dict_with_properties(
>  				WPAS_DBUS_INTERFACE_MAX) &&
>  		    dsc->access != W && dsc->getter) {
>  			reply = dsc->getter(NULL, user_data);
> -			if (!reply)
> +			if (!reply) {
> +				wpa_printf(MSG_ERROR, "dbus: %s: Cannot get "
> +					   "value of property %s", __func__,
> +					   dsc->dbus_property);
>  				continue;
> +			}
>  
>  			if (dbus_message_get_type(reply) ==
>  			    DBUS_MESSAGE_TYPE_ERROR) {
> +				wpa_printf(MSG_ERROR, "dbus: %s: Cannot get "
> +					   "value of property %s", __func__,
> +					   dsc->dbus_property);
>  				dbus_message_unref(reply);
>  				continue;
>  			}
> @@ -647,6 +654,8 @@ static void put_changed_properties(const struct wpa_dbus_object_desc *obj_dsc,
>  			wpa_printf(MSG_ERROR, "dbus: %s: Cannot get new value "
>  				   "of property %s", __func__,
>  				   dsc->dbus_property);
> +			if (getter_reply)
> +				dbus_message_unref(getter_reply);
>  			continue;
>  		}
>  
> @@ -670,6 +679,9 @@ static void put_changed_properties(const struct wpa_dbus_object_desc *obj_dsc,
>  	return;
>  
>  err:
> +	if (getter_reply)
> +		dbus_message_unref(getter_reply);
> +
>  	wpa_printf(MSG_ERROR, "dbus: %s: Cannot construct signal", __func__);
>  }
>  




More information about the HostAP mailing list