The problem seems pretty simple but I haven't figured it out yet.
I'm using wxWidgets to make a gui and this function gets called when I press enter while in a text field.
void Camera_Settings::on_exposure(wxCommandEvent &event)
{
wxString temp = exposure->GetValue();
char *value = (char *)temp.mb_str();
char *hex_string = new char[3];
itoa(atoi(value), hex_string, 16);
string final = "ly3";
final += hex_string;
final += "\r";
camera->command((char *)final.c_str());
}
For anyone unfamiliar with wxWidgets I'll just say that wxString is a string and (char *)temp.mb_str() gets the c string it represents.
When I run the program and get the message that I have a memory leak, I pretty sure it has to do with the hex_string since I have a leak of 3 bytes for each time I call this function. But if I simply call delete []hex_string at the end of the function my program crashes and says that it tried to write to the end of the heap.