From 3e87bd5478595af09d51bfe58ed166d2dfbb6b7b Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 2 Jan 2010 17:17:00 +0200 Subject: [PATCH] dbus: Use stack for temporary object path This is small enough buffer to not require more complex dynamic allocation for temporary use. --- wpa_supplicant/dbus/dbus_new.c | 35 ++++--------------------- wpa_supplicant/dbus/dbus_new_handlers.c | 31 +++++----------------- wpa_supplicant/dbus/dbus_old_handlers.c | 10 +------ 3 files changed, 12 insertions(+), 64 deletions(-) diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c index 3d5a01640..a9abd882d 100644 --- a/wpa_supplicant/dbus/dbus_new.c +++ b/wpa_supplicant/dbus/dbus_new.c @@ -1060,10 +1060,8 @@ int wpas_dbus_register_network(struct wpa_supplicant *wpa_s, { struct wpas_dbus_priv *ctrl_iface; struct wpa_dbus_object_desc *obj_desc; - struct network_handler_args *arg = NULL; - - char *net_obj_path; + char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX]; /* Do nothing if the control interface is not turned on */ if (wpa_s == NULL || wpa_s->global == NULL) @@ -1072,9 +1070,6 @@ int wpas_dbus_register_network(struct wpa_supplicant *wpa_s, if (ctrl_iface == NULL) return 0; - net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - if (net_obj_path == NULL) - return -1; os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", wpa_s->dbus_new_path, ssid->id); @@ -1109,11 +1104,9 @@ int wpas_dbus_register_network(struct wpa_supplicant *wpa_s, wpas_dbus_signal_network_added(wpa_s, ssid->id); - os_free(net_obj_path); return 0; err: - os_free(net_obj_path); os_free(obj_desc); os_free(arg); return -1; @@ -1131,7 +1124,7 @@ err: int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid) { struct wpas_dbus_priv *ctrl_iface; - char *net_obj_path; + char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX]; int ret; /* Do nothing if the control interface is not turned on */ @@ -1141,9 +1134,6 @@ int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid) if (ctrl_iface == NULL) return 0; - net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - if (net_obj_path == NULL) - return -1; os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", wpa_s->dbus_new_path, nid); @@ -1155,7 +1145,6 @@ int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid) if (!ret) wpas_dbus_signal_network_removed(wpa_s, nid); - os_free(net_obj_path); return ret; } @@ -1239,7 +1228,7 @@ int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s, u8 bssid[ETH_ALEN], unsigned int id) { struct wpas_dbus_priv *ctrl_iface; - char *bss_obj_path; + char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX]; /* Do nothing if the control interface is not turned on */ if (wpa_s == NULL || wpa_s->global == NULL) @@ -1248,10 +1237,6 @@ int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s, if (ctrl_iface == NULL) return 0; - bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - if (bss_obj_path == NULL) - return -1; - os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u", wpa_s->dbus_new_path, id); @@ -1259,16 +1244,13 @@ int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s, wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'", bss_obj_path); if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) { - wpa_printf(MSG_ERROR, - "Cannot unregister BSSID dbus object %s.", + wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s", bss_obj_path); - os_free(bss_obj_path); return -1; } wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path); - os_free(bss_obj_path); return 0; } @@ -1287,8 +1269,7 @@ int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s, { struct wpas_dbus_priv *ctrl_iface; struct wpa_dbus_object_desc *obj_desc; - char *bss_obj_path; - + char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX]; struct bss_handler_args *arg = NULL; /* Do nothing if the control interface is not turned on */ @@ -1298,10 +1279,6 @@ int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s, if (ctrl_iface == NULL) return 0; - bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - if (bss_obj_path == NULL) - return -1; - os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u", wpa_s->dbus_new_path, id); @@ -1338,11 +1315,9 @@ int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s, wpas_dbus_signal_bss_added(wpa_s, bss_obj_path); - os_free(bss_obj_path); return 0; err: - os_free(bss_obj_path); os_free(obj_desc); os_free(arg); return -1; diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index 315caec45..cbb52f641 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -1300,14 +1300,7 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message, DBusMessage *reply = NULL; DBusMessageIter iter; struct wpa_ssid *ssid = NULL; - char *path = NULL; - - path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - if (path == NULL) { - reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, - NULL); - goto err; - } + char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf; dbus_message_iter_init(message, &iter); @@ -1352,7 +1345,6 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message, goto err; } - os_free(path); return reply; err: @@ -1360,7 +1352,6 @@ err: wpas_notify_network_removed(wpa_s, ssid); wpa_config_remove_network(wpa_s->conf, ssid->id); } - os_free(path); return reply; } @@ -2084,12 +2075,8 @@ DBusMessage * wpas_dbus_getter_driver(DBusMessage *message, DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message, struct wpa_supplicant *wpa_s) { - DBusMessage *reply = NULL; - char *bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - - if (bss_obj_path == NULL) - return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, - NULL); + DBusMessage *reply; + char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf; if (wpa_s->current_bss) os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, @@ -2102,7 +2089,6 @@ DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message, DBUS_TYPE_OBJECT_PATH, &bss_obj_path); - os_free(bss_obj_path); return reply; } @@ -2119,12 +2105,8 @@ DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message, DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message, struct wpa_supplicant *wpa_s) { - DBusMessage *reply = NULL; - char *net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - - if (net_obj_path == NULL) - return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, - NULL); + DBusMessage *reply; + char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf; if (wpa_s->current_ssid) os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, @@ -2137,7 +2119,6 @@ DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message, DBUS_TYPE_OBJECT_PATH, &net_obj_path); - os_free(net_obj_path); return reply; } @@ -2211,7 +2192,7 @@ DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message, paths, wpa_s->num_bss); out: - while(i) + while (i) os_free(paths[--i]); os_free(paths); return reply; diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c b/wpa_supplicant/dbus/dbus_old_handlers.c index f9d3bcdd6..8e1f7b0a2 100644 --- a/wpa_supplicant/dbus/dbus_old_handlers.c +++ b/wpa_supplicant/dbus/dbus_old_handlers.c @@ -787,14 +787,7 @@ DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message, { DBusMessage *reply = NULL; struct wpa_ssid *ssid; - char *path = NULL; - - path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); - if (path == NULL) { - wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan " - "results signal"); - goto out; - } + char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf; ssid = wpa_config_add_network(wpa_s->conf); if (ssid == NULL) { @@ -818,7 +811,6 @@ DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message, &path, DBUS_TYPE_INVALID); out: - os_free(path); return reply; }