remove malloc where not needed

pull/326/head
Thorsten von Eicken 8 years ago
parent 6bdfaf933e
commit c0cd698860
No known key found for this signature in database
GPG Key ID: C7F972A59D834B46
  1. 38
      cmd/handlers.c

@ -295,40 +295,32 @@ static void ICACHE_FLASH_ATTR cmdWifiSelectSSID(CmdPacket *cmd) {
CmdRequest req; CmdRequest req;
cmdRequest(&req, cmd); cmdRequest(&req, cmd);
int argc = cmdGetArgc(&req); int argc = cmdGetArgc(&req);
char *ssid, *pass; char ssid[33], pass[65];
if (argc != 2) if (argc != 2) return;
return;
int len = cmdArgLen(&req); int len = cmdArgLen(&req);
if (len == 1) { if (len == 1) {
// Assume this is the index // Assume this is the index
uint8_t ix; uint8_t ix;
cmdPopArg(&req, &ix, 1); cmdPopArg(&req, &ix, 1);
len = cmdArgLen(&req); wifiGetApName(ix, ssid);
pass = (char *)os_malloc(len+1); ssid[32] = '\0';
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);
} else { } else {
ssid = os_malloc(len+1); // Longer than 1 byte: must be SSID
if (len > 32) return;
cmdPopArg(&req, ssid, len); cmdPopArg(&req, ssid, len);
ssid[len] = 0; ssid[len] = 0;
}
len = cmdArgLen(&req); // Extract password from message
pass = (char *)os_malloc(len+2); len = cmdArgLen(&req);
cmdPopArg(&req, pass, len); if (len > 64) return;
pass[len] = 0; cmdPopArg(&req, pass, len);
pass[len] = 0;
DBG("SelectSSID(%s,%s)", ssid, pass); DBG("SelectSSID(%d,%s)", ix, pass);
connectToNetwork(ssid, pass); connectToNetwork(ssid, pass);
}
} }
#if 0 #if 0
@ -364,7 +356,7 @@ static void ICACHE_FLASH_ATTR cmdWifiSignalStrength(CmdPacket *cmd) {
cmdResponseEnd(); cmdResponseEnd();
} }
// //
static void ICACHE_FLASH_ATTR cmdWifiQuerySSID(CmdPacket *cmd) { static void ICACHE_FLASH_ATTR cmdWifiQuerySSID(CmdPacket *cmd) {
CmdRequest req; CmdRequest req;
cmdRequest(&req, cmd); cmdRequest(&req, cmd);

Loading…
Cancel
Save