From 359f6b3a210a7b3c70b36c7cb443cf4931cfbabe Mon Sep 17 00:00:00 2001 From: David Cermak Date: Sun, 15 Sep 2019 09:47:43 +0200 Subject: [PATCH] esp_netif: add consistency checks for configs and interface key duplication --- components/esp_netif/lwip/esp_netif_lwip.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 41080148a7..269375e0f9 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -358,19 +358,27 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) { // mandatory configuration must be provided when creating esp_netif object - if (esp_netif_config == NULL) { + if (esp_netif_config == NULL || + esp_netif_config->base->if_key == NULL || + NULL != esp_netif_get_handle_from_ifkey(esp_netif_config->base->if_key)) { + ESP_LOGE(TAG, "%s: Failed to configure netif with config=%p (config or if_key is NULL or duplicate key)", + __func__, esp_netif_config); return NULL; } // Create parent esp-netif object esp_netif_t *esp_netif = calloc(1, sizeof(struct esp_netif_obj)); if (!esp_netif) { + ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(struct esp_netif_obj), + esp_get_free_heap_size()); return NULL; } // Create ip info esp_netif_ip_info_t *ip_info = calloc(1, sizeof(esp_netif_ip_info_t)); if (!ip_info) { + ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(esp_netif_ip_info_t), + esp_get_free_heap_size()); free(esp_netif); return NULL; } @@ -379,6 +387,8 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) // creating another ip info (to store old ip) ip_info = calloc(1, sizeof(esp_netif_ip_info_t)); if (!ip_info) { + ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(esp_netif_ip_info_t), + esp_get_free_heap_size()); free(esp_netif->ip_info); free(esp_netif); return NULL; @@ -388,6 +398,8 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) // Create underlying lwip netif struct netif * lwip_netif = calloc(1, sizeof(struct netif)); if (!lwip_netif) { + ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(struct netif), + esp_get_free_heap_size()); free(esp_netif->ip_info_old); free(esp_netif->ip_info); free(esp_netif);