From c0cd6988601db1366c8b9182932a259458b33008 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 15 Jun 2017 20:45:50 -0700 Subject: [PATCH] remove malloc where not needed --- cmd/handlers.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/cmd/handlers.c b/cmd/handlers.c index 32e03c3..abeac8d 100644 --- a/cmd/handlers.c +++ b/cmd/handlers.c @@ -295,40 +295,32 @@ static void ICACHE_FLASH_ATTR cmdWifiSelectSSID(CmdPacket *cmd) { CmdRequest req; cmdRequest(&req, cmd); int argc = cmdGetArgc(&req); - char *ssid, *pass; + char ssid[33], pass[65]; - if (argc != 2) - return; + if (argc != 2) return; int len = cmdArgLen(&req); if (len == 1) { // Assume this is the index uint8_t ix; cmdPopArg(&req, &ix, 1); - len = cmdArgLen(&req); - pass = (char *)os_malloc(len+1); - cmdPopArg(&req, pass, len); - pass[len] = 0; - - DBG("SelectSSID(%d,%s)", ix, pass); - - char myssid[33]; - wifiGetApName(ix, myssid); - myssid[32] = '\0'; - connectToNetwork(myssid, pass); + wifiGetApName(ix, ssid); + ssid[32] = '\0'; } else { - ssid = os_malloc(len+1); + // Longer than 1 byte: must be SSID + if (len > 32) return; cmdPopArg(&req, ssid, len); ssid[len] = 0; + } - len = cmdArgLen(&req); - pass = (char *)os_malloc(len+2); - cmdPopArg(&req, pass, len); - pass[len] = 0; + // Extract password from message + len = cmdArgLen(&req); + if (len > 64) return; + cmdPopArg(&req, pass, len); + pass[len] = 0; - DBG("SelectSSID(%s,%s)", ssid, pass); - connectToNetwork(ssid, pass); - } + DBG("SelectSSID(%d,%s)", ix, pass); + connectToNetwork(ssid, pass); } #if 0 @@ -364,7 +356,7 @@ static void ICACHE_FLASH_ATTR cmdWifiSignalStrength(CmdPacket *cmd) { cmdResponseEnd(); } -// +// static void ICACHE_FLASH_ATTR cmdWifiQuerySSID(CmdPacket *cmd) { CmdRequest req; cmdRequest(&req, cmd);