fix memory breakages after previous change

This commit is contained in:
Stephen Birarda 2013-05-13 16:29:43 -07:00
parent 0f9d72e2c1
commit cc4492bad8

View file

@ -66,7 +66,7 @@ int main(int argc, const char* argv[]) {
char deviceAddress[INET_ADDRSTRLEN] = {}; char deviceAddress[INET_ADDRSTRLEN] = {};
int socketPort = 0; int socketPort = 0;
int numMatches = sscanf(senderData, "Available %s%[^:]:%d %s", int numMatches = sscanf(senderData, "Available %s %[^:]:%d %s",
tempDevice.identifier, tempDevice.identifier,
deviceAddress, deviceAddress,
&socketPort, &socketPort,
@ -74,23 +74,24 @@ int main(int argc, const char* argv[]) {
if (numMatches >= 3) { if (numMatches >= 3) {
// if we have fewer than 3 matches the packet wasn't properly formatted // if we have fewer than 3 matches the packet wasn't properly formatted
// otherwise copy the tempDevice to the persisting lastDevice
*::lastDevice = tempDevice;
// setup the localSocket for the pairing device // setup the localSocket for the pairing device
::lastDevice->localSocket.sin_family = AF_INET; tempDevice.localSocket.sin_family = AF_INET;
inet_pton(AF_INET, deviceAddress, &::lastDevice); inet_pton(AF_INET, deviceAddress, &::lastDevice);
::lastDevice->localSocket.sin_port = socketPort; tempDevice.localSocket.sin_port = socketPort;
// store this device's sending socket so we can talk back to it // store this device's sending socket so we can talk back to it
::lastDevice->sendingSocket = senderSocket; tempDevice.sendingSocket = senderSocket;
// push this new device into the vector // push this new device into the vector
printf("Adding device %s (%s) - %s:%d to list\n", printf("New last device is %s (%s) at %s:%d\n",
::lastDevice->identifier, tempDevice.identifier,
::lastDevice->name, tempDevice.name,
deviceAddress, deviceAddress,
socketPort); socketPort);
// copy the tempDevice to the persisting lastDevice
::lastDevice = new PairableDevice(tempDevice);
if (::lastClient) { if (::lastClient) {
sendLastClientToLastDevice(); sendLastClientToLastDevice();
@ -107,10 +108,10 @@ int main(int argc, const char* argv[]) {
&tempClient.port); &tempClient.port);
if (requestorMatches == 2) { if (requestorMatches == 2) {
// good data, copy the tempClient to the persisting lastInterfaceClient // good data, copy the tempClient to the persisting lastInterfaceClient
*::lastClient = tempClient; ::lastClient = new RequestingClient(tempClient);
printf("Find request from interface client at %s:%d\n", printf("New last client is at %s:%d\n",
::lastClient->address, ::lastClient->address,
::lastClient->port); ::lastClient->port);