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. 28
      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;
}
// Extract password from message
len = cmdArgLen(&req); len = cmdArgLen(&req);
pass = (char *)os_malloc(len+2); if (len > 64) return;
cmdPopArg(&req, pass, len); cmdPopArg(&req, pass, len);
pass[len] = 0; 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

Loading…
Cancel
Save