Hi,
I recently read that memory leaks can occur when using the string stream str() member function (http://www.troubleshooters.com/codecorn/memleak.htm). Is this true only for passing pointers or references to the created string object? Is this true at all?
For example, can anyone see if the following code would cause a leak if the first open function is called?
short SerialPort::open(int portNum, const string &settings){
stringstream deviceName;
deviceName << "\\\\.\\COM" << portNum; // weird \\.\ allows emulated ports to work
return open(deviceName.str(), settings);
}
short SerialPort::open(const string &deviceName, const string &settings){
cout << "SerialPort::open()" << endl;
hComm = CreateFile(deviceName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
DCB dcb;
// the following commented lines have been abbreviated
//GetCommState(hComm, &dcb)
//BuildCommDCB(settings.c_str(), &dcb)
//SetCommState(hComm, &dcb)
//SetCommTimeouts(hComm, &timeouts)
cout << "Serial Port " << deviceName << " opened OK" << endl;
return 0;
}
Thanks for any insight!
-Doug