[PATCH] Fix memory leak on invalid interface error path

Masashi Honma honma
Thu Dec 9 18:49:15 PST 2010


(2010/12/10 11:48), Masashi Honma wrote:
> Hello.
>
> The hostapd produces following error messages when I specify
> nonexistent interface name to hostapd.conf "interface=" field.

Furthermore, this patch can catch the error at more early phase.


diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 9bd4061..28876ce 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1680,7 +1680,7 @@ static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
  }
  
  
-static void nl80211_get_phy_name(struct wpa_driver_nl80211_data *drv)
+static int nl80211_get_phy_name(struct wpa_driver_nl80211_data *drv)
  {
  	/* Find phy (radio) to which this interface belongs */
  	char buf[90], *pos;
@@ -1691,17 +1691,17 @@ static void nl80211_get_phy_name(struct wpa_driver_nl80211_data *drv)
  		 drv->first_bss.ifname);
  	f = open(buf, O_RDONLY);
  	if (f < 0) {
-		wpa_printf(MSG_DEBUG, "Could not open file %s: %s",
+		wpa_printf(MSG_ERROR, "Could not open file %s: %s",
  			   buf, strerror(errno));
-		return;
+		return -1;
  	}
  
  	rv = read(f, drv->phyname, sizeof(drv->phyname) - 1);
  	close(f);
  	if (rv < 0) {
-		wpa_printf(MSG_DEBUG, "Could not read file %s: %s",
+		wpa_printf(MSG_ERROR, "Could not read file %s: %s",
  			   buf, strerror(errno));
-		return;
+		return -1;
  	}
  
  	drv->phyname[rv] = '\0';
@@ -1710,6 +1710,7 @@ static void nl80211_get_phy_name(struct wpa_driver_nl80211_data *drv)
  		*pos = '\0';
  	wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
  		   drv->first_bss.ifname, drv->phyname);
+	return 0;
  }
  
  
@@ -1748,7 +1749,8 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
  		return NULL;
  	}
  
-	nl80211_get_phy_name(drv);
+	if (nl80211_get_phy_name(drv) < 0)
+		goto failed;
  
  	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
  	if (drv->ioctl_sock < 0) {
@@ -1927,7 +1929,8 @@ wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
  			       1, IF_OPER_DORMANT);
  #endif /* HOSTAPD */
  
-	linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, drv->addr);
+	if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, drv->addr))
+		return -1;
  
  	if (nl80211_register_action_frames(drv) < 0) {
  		wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "

Regards,
Masashi Honma.



More information about the Hostap mailing list